Re: Beep ( frequency, duration)

2014-12-29 Thread Michael Crawford
The following plays a 441 Hz tone directly into the audio driver.

If you alter this code, it is important not to block requests from the
audio driver for more samples.  While this source runs in userspace,
and it supplies data from userspace, the requests for samples seem to
be coming from a hardware interrupt task.

I had the idea I could set a mutex when I ran out of samples with the
result that I scared the crap out of my dogs as well as very nearly
set my MacBook Pro on fire.

I think I wrote this for Tiger.  I haven't tried it on more-recent systems.

Mike

=

// BirthCry.cpp - The very first sound Ogg Frog made!

/* Ogg Frog: Free Music Ripping, Encoding and Backup Program
 *
 * Copyright (C) 2006 Michael David Crawford.
 *
 * Do What Thou Wilt Is The Whole Of The Law.
 * (Relicensed by the copyright holder from the GPLv2.)
 */
#include 
#include 
#include 
#include 

int OpenOutput( AudioUnit &output );
int CloseOutput( AudioUnit output );

OSStatus PCMData( void * & nbsp;&nb sp; inRefCon,
 &n bsp;  AudioUnitRenderActionFlags *ioActionFlags,
 &n bsp;  const AudioTimeStamp *inTimeStamp,
 &n bsp;  UInt32&n bsp;
&nbs p;  inBusNumber,
 &n bsp;  UInt32&n bsp;
&nbs p;  inNumberFrames,
 &n bsp;  AudioBufferList * & nbsp;  ioData);

using std::cerr;
using std::cout;

int main( int argc, char **argv )
{
AudioUnit output;

if ( OpenOutput( output ) != 0 ){
cerr << "OpenOutput failed\n";
return -1;
}

ComponentResult cResult;

if ( noErr != ( cResult = AudioOutputUnitStart( output ) ) ){
cerr << "AudioOutputUnitStart failed\n";
return -1;
}

usleep( 10 * 1000 * 1000 );

if ( noErr != ( cResult = AudioOutputUnitStop( output ) ) ){
cerr << "AudioOutputUnitStop failed\n";
return -1;
}

if ( CloseOutput( output ) != 0 ){
cerr << "CloseOutput failed\n";
return -1;
}

return 0;
}

int OpenOutput( AudioUnit &output )
{
ComponentDescription cd;

cd.componentType = kAudioUnitType_Output;
cd.componentSubType = kAudioUnitSubType_DefaultOutput;
cd.componentManufacturer = kAudioUnitManufacturer_Apple;
cd.componentFlags = 0;
cd.componentFlagsMask = 0;

Component comp = FindNextComponent( NULL, &cd );
if ( comp == NULL )
return -1;

OSStatus result;

result = OpenAComponent( comp, &output );
if ( noErr != result )
return -1;

result = AudioUnitInitialize( output );
if ( noErr != result )
return -1;

AURenderCallbackStruct callbackData;
callbackData.inputProc = PCMData;
callbackData.inputProcRefCon = NULL;

if ( ( result = AudioUnitSetProperty( output,
 &n bsp;&nbs p;
kAudioUnitProperty_SetRenderCallback,
 &n bsp;&nbs p; kAudioUnitScope_Global,
 &n bsp;&nbs p; 0,
 &n bsp;&nbs p; &callbackData,
 &n bsp;&nbs p; sizeof( callbackData ) ) )
!= noErr ){
return -1;
}

AudioStreamBasicDescription streamDesc;

UInt32 streamDescSize = sizeof( streamDesc );

if ( noErr != ( result = AudioUnitGetProperty( output,
 &n bsp;&nbs p;
kAudioUnitProperty_StreamFormat,
 &n bsp;&nbs p;
kAudioUnitScope_Global,
 &n bsp;&nbs p;  0,
 &n bsp;&nbs p;  &streamDesc,
 &n bsp;&nbs p;
&streamDescSize ) ) ){
return -1;
}
 &n bsp;&nbs p;
return 0;
}

int CloseOutput( AudioUnit output )
{
ComponentResult cResult;
OSErr err;

if ( noErr != ( cResult = AudioUnitUninitialize( output ) ) ){
return -1;
}

if ( noErr != ( err = CloseComponent( output ) ) ){
return -1;
}

return 0;
}

OSStatus PCMData( void *inRefCon,
 &n bsp;  AudioUnitRenderActionFlags *ioActionFlags,
 &n bsp;  const AudioTimeStamp *inTimeStamp,
 &n bsp;  UInt32&n bsp;
&nbs p;  inBusNumber,
 &n bsp;  UInt32&n bsp;
&nbs p;  inNumberFrames,
 &n bsp;  AudioBufferList * & nbsp;  ioData)
{
Float64 now = inTimeStamp->mSampleTime;

Float64 twoPi = 2 * 3.1415926535;

Float32 *sample = (Float32*)( ioData->mBuffers[ 0 ].mData );

for ( int i = 0; i < inNumberFrames; ++i ){

*sample++ = sin( twoPi * ( now / 100.0 ) );

now += 1.0;
}

return noErr;
}
Michael David Crawford, Consulting Software Engineer
mdcrawf...@gmail.com
http://www.warplife.com/mdc/

   Available for Software Development in the Portland, Oregon Metropolitan
Area.


On Sun

Re: Beep ( frequency, duration)

2014-12-29 Thread Jens Alfke

> On Dec 29, 2014, at 2:12 AM, Michael Crawford  wrote:
> 
> While this source runs in userspace,
> and it supplies data from userspace, the requests for samples seem to
> be coming from a hardware interrupt task.

It's not quite that low-level! It's a thread, but a super-high-priority 
(real-time) one managed by CoreAudio's hardware abstraction layer (HAL). Which 
you should _not_ ever block, or system audio will get screwed up. (That's one 
of the difficulties doing audio at that level — you can't call any I/O from 
that callback, so you have to run another thread to read the audio data from a 
file/socket/whatever and queue it. Thank god we have AVFoundation now to do 
that kind of stuff.)

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Beep ( frequency, duration)

2014-12-29 Thread Paul Scott


> On Dec 29, 2014, at 2:12 AM, Michael Crawford  wrote:
> 
> OpenAComponent( comp, &output )
> CloseComponent( output )

These are deprecated since — I believe — OS X 10.8.

You should probably use the iOS compatible functions:

AudioComponentInstanceNew(comp, &output)
AudioComponentInstanceDispose(output)

Paul

smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Beep ( frequency, duration)

2014-12-29 Thread Wim Lewis

On Dec 29, 2014, at 2:12 AM, Michael Crawford  wrote:
>for ( int i = 0; i < inNumberFrames; ++i ){
>   *sample++ = sin( twoPi * ( now / 100.0 ) );
>   now += 1.0;
>}


Depending on what your overall goal is, it might be easier to use the software 
MIDI synthesizer instead of computing the samples yourself— if you want a 
bandlimited start and end, or even a music-like attack/decay/release envelope 
or a spectrum more complicated than a pure sine wave, using something like the 
AVMIDIPlayer class might free you from a bunch of realtime requirements and 
bookkeeping.

(On the other hand, I’ve never tried using it, so I don’t know if its simple 
API hides a well of frustration.)


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Beep ( frequency, duration)

2014-12-29 Thread Michael Crawford
> Depending on what your overall goal is

In this particular case, all I wanted was to learn how to spit audio
samples directly into the sound driver.

My input does come from another thread, reading ogg vorbis, flac, wave
or mp3 files that write into a circular buffer.  When the buffer is
full a mutex blocks the input thread; when the buffer is empty it
feeds silence - zeros - into the sound driver.
Michael David Crawford, Consulting Software Engineer
mdcrawf...@gmail.com
http://www.warplife.com/mdc/

   Available for Software Development in the Portland, Oregon Metropolitan
Area.


On Mon, Dec 29, 2014 at 1:14 PM, Wim Lewis  wrote:
>
> On Dec 29, 2014, at 2:12 AM, Michael Crawford  wrote:
>>for ( int i = 0; i < inNumberFrames; ++i ){
>>   *sample++ = sin( twoPi * ( now / 100.0 ) );
>>   now += 1.0;
>>}
>
>
> Depending on what your overall goal is, it might be easier to use the 
> software MIDI synthesizer instead of computing the samples yourself-- if you 
> want a bandlimited start and end, or even a music-like attack/decay/release 
> envelope or a spectrum more complicated than a pure sine wave, using 
> something like the AVMIDIPlayer class might free you from a bunch of realtime 
> requirements and bookkeeping.
>
> (On the other hand, I've never tried using it, so I don't know if its simple 
> API hides a well of frustration.)
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/mdcrawford%40gmail.com
>
> This email sent to mdcrawf...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Application Crashing Under Mavericks, but not Yosemite (Entitlements Issue?)

2014-12-29 Thread SevenBits
Hey guys,

Maybe my experience is simply too narrow to be able to know how to resolve
this issue, but I'm seriously confused by an issue I'm seeing in my Cocoa
app.

I just released version 3.0 of Mac Linux USB Loader, my app, and it
supports 10.8-10.10. Yesterday I received a bug report that the application
cannot open documents under Mavericks, but everything works fine under
Yosemite. I have just installed a fresh copy of Mavericks, and I can
confirm that this is the case, so it is definitely not operating system
corruption. The app is released by direct distribution.

The app passes Gatekeeper and launches just fine (it is signed with my
Developer ID), and all other features appear to work, except for this quite
crucial one. When I look in the console, I see the following error messages
which concern me:

12/29/14 7:08:30.971 PM librariand[205]: client process 257 does not have a
valid com.apple.developer.ubiquity-container-identifiers entitlement
12/29/14 7:08:30.971 PM librariand[205]: error in
handle_container_path_request: LibrarianErrorDomain/9/The client process
does not have a valid com.apple.developer.ubiquity-container-identifiers
entitlement

The thing is, I am not using iCloud and that entitlement isn't even present
in my entitlements file. Those messages are from just opening the
NSOpenPanel, and doing anything else; clearly, Powerbox is flipping out.
When I click Open, I get some new messages and nothing shows up (but the
application does not crash). Here are the messages that appear to be
relevant:

12/29/14 7:09:19.969 PM Mac Linux USB Loader[257]: view service marshal for
 failed to forget accessibility connection
due to Error Domain=NSCocoaErrorDomain Code=4099 "Couldn’t communicate with
a helper application." (The connection was invalidated from this process.)
UserInfo=0x60800046e380 {NSDebugDescription=The connection was invalidated
from this process.}
timestamp: 19:09:19.969 Monday 29 December 2014
process/thread/queue: Mac Linux USB Loader (257) / 0x103535000 /
com.apple.NSXPCConnection.user.endpoint
code: line 2972 of /SourceCache/ViewBridge/ViewBridge-46.2/NSRemoteView.m
in __57-[NSRemoteView
viewServiceMarshalProxy:withErrorHandler:]_block_invoke
domain: communications-failure

I've attached the full log file. Could anyone shed any light on this?

Happy holidays,

-- SevenBits

P.S.: I posted this message to this list because this appears to be an
issue with my app's code. My apologies if this is the wrong place.
12/29/14 7:08:30.971 PM librariand[205]: client process 257 does not have a 
valid com.apple.developer.ubiquity-container-identifiers entitlement
12/29/14 7:08:30.971 PM librariand[205]: error in 
handle_container_path_request: LibrarianErrorDomain/9/The client process does 
not have a valid com.apple.developer.ubiquity-container-identifiers entitlement
12/29/14 7:08:31.168 PM WindowServer[92]: CGXSetWindowTransform: Operation on a 
window 0x5a requiring rights kCGSWindowRightPresenter by caller 
com.apple.appkit.xpc.openAndSav
12/29/14 7:08:31.168 PM com.apple.appkit.xpc.openAndSavePanelService[287]: 
CGSSetWindowTransformAtPlacement: Failed
12/29/14 7:08:31.168 PM com.apple.appkit.xpc.openAndSavePanelService[287]: 
ERROR: CGSSetWindowTransformAtPlacement() returned 1001
12/29/14 7:08:31.168 PM WindowServer[92]: CGXSetWindowListAlpha: Operation on a 
window 0x5a requiring rights kCGSWindowRightPresenter by caller 
com.apple.appkit.xpc.openAndSav
12/29/14 7:08:31.186 PM WindowServer[92]: CGXSetWindowTransform: Operation on a 
window 0x5a requiring rights kCGSWindowRightPresenter by caller 
com.apple.appkit.xpc.openAndSav
12/29/14 7:08:31.186 PM com.apple.appkit.xpc.openAndSavePanelService[287]: 
CGSSetWindowTransformAtPlacement: Failed
12/29/14 7:08:31.187 PM com.apple.appkit.xpc.openAndSavePanelService[287]: 
ERROR: CGSSetWindowTransformAtPlacement() returned 1001
12/29/14 7:08:31.187 PM WindowServer[92]: CGXSetWindowListAlpha: Operation on a 
window 0x5a requiring rights kCGSWindowRightPresenter by caller 
com.apple.appkit.xpc.openAndSav
12/29/14 7:08:31.206 PM WindowServer[92]: CGXSetWindowTransform: Operation on a 
window 0x5a requiring rights kCGSWindowRightPresenter by caller 
com.apple.appkit.xpc.openAndSav
12/29/14 7:08:31.206 PM com.apple.appkit.xpc.openAndSavePanelService[287]: 
CGSSetWindowTransformAtPlacement: Failed
12/29/14 7:08:31.206 PM com.apple.appkit.xpc.openAndSavePanelService[287]: 
ERROR: CGSSetWindowTransformAtPlacement() returned 1001
12/29/14 7:08:31.206 PM WindowServer[92]: CGXSetWindowListAlpha: Operation on a 
window 0x5a requiring rights kCGSWindowRightPresenter by caller 
com.apple.appkit.xpc.openAndSav
12/29/14 7:08:31.222 PM WindowServer[92]: CGXSetWindowTransform: Operation on a 
window 0x5a requiring rights kCGSWindowRightPresenter by caller 
com.apple.appkit.xpc.openAndSav
12/29/14 7:08:31.223 PM com.apple.appkit.xpc.openAndSavePanelService[287]: 
CGSSetWindowTransformAtPlacement: Failed
12/29/14 7:08:31.223 PM com.apple.appkit.xpc.ope

Re: Application Crashing Under Mavericks, but not Yosemite (Entitlements Issue?)

2014-12-29 Thread Roland King

> On 30 Dec 2014, at 08:27, SevenBits  wrote:
> 
> Hey guys,
> 
> Maybe my experience is simply too narrow to be able to know how to resolve
> this issue, but I'm seriously confused by an issue I'm seeing in my Cocoa
> app.

What’s going on at the point the actual exception is thrown near the bottom of 
the logfile? That appears to be in your app’s windowDidLoad code. Is that a 
result of the earlier errors or a separate issue? Something somewhere is 
calling containsString: on something inappropriate. Can you symbolicate that 
(hahahaha yeah right, didn’t Xcode used to do that for you) and rule out that’s 
a contributing factor? 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Application Crashing Under Mavericks, but not Yosemite (Entitlements Issue?)

2014-12-29 Thread Quincey Morris
On Dec 29, 2014, at 16:27 , SevenBits  wrote:
> 
> The thing is, I am not using iCloud and that entitlement isn't even present
> in my entitlements file. Those messages are from just opening the
> NSOpenPanel, and doing anything else; clearly, Powerbox is flipping out.

AFAIK, NSOpenPanel originally (that is, in 10.8.6 or so) did *not* use Powerbox 
in non-sandboxed apps. Whether that has changed since then, I don’t know.

> Here are the messages that appear to be
> relevant:
> 
> 12/29/14 7:09:19.969 PM Mac Linux USB Loader[257]: view service marshal for
>  failed to forget accessibility connection
> due to Error Domain=NSCocoaErrorDomain Code=4099 "Couldn’t communicate with
> a helper application." (The connection was invalidated from this process.)
> UserInfo=0x60800046e380 {NSDebugDescription=The connection was invalidated
> from this process.}
> timestamp: 19:09:19.969 Monday 29 December 2014
> process/thread/queue: Mac Linux USB Loader (257) / 0x103535000 /
> com.apple.NSXPCConnection.user.endpoint
> code: line 2972 of /SourceCache/ViewBridge/ViewBridge-46.2/NSRemoteView.m
> in __57-[NSRemoteView
> viewServiceMarshalProxy:withErrorHandler:]_block_invoke
> domain: communications-failure

I vaguely recall seeing these messages reported in a Forum post recently, in 
relation to a NSOpenPanel crash, suggesting the IPC here *is* to Powerbox, 
which I find a little odd.

This smells a little bit like a problem where functionality depends on what SDK 
the app is linked against.

— What happens, if your app is linked against the 10.10 SDK (deployment target 
10.8+), if you link it against the 10.9 SDK instead?

— Or, if your app is linked against the 10.9 SDK  (deployment target 10.8 or 
earlier), what happens if you link it against the 10.8 SDK instead? (This means 
using an earlier Xcode, though.)

Or, even simpler, perhaps you’ve accidentally used 10.10 API somewhere that 
doesn’t exist earlier. Building against the 10.9 SDK should uncover such 
errors, too.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Application Crashing Under Mavericks, but not Yosemite (Entitlements Issue?)

2014-12-29 Thread Roland King

> 
> I'm currently trying to set up developer tools on my new, fresh Mavericks 
> installation, but there is only one place where containsString: is being 
> called, at least by my code, and its here:
> 
> - (void)detectDistributionFamily {
>   SBLinuxDistribution family = [SBUSBDevice 
> distributionTypeForISOName:self.fileURL.absoluteString];
>   switch (family) {
>   case SBDistributionUbuntu:
>   [self.distributionSelectorPopup 
> selectItemWithTitle:@"Ubuntu"];
>   break;
>   case SBDistributionDebian:
>   case SBDistributionTails:
>   [self.distributionSelectorPopup 
> selectItemWithTitle:@"Debian"];
>   break;
>   case SBDistributionUnknown:
>   default:
>   [self.distributionSelectorPopup 
> selectItemWithTitle:@"Other"];
>   break;
>   }
> 
>   if ([[[self.fileURL path] lastPathComponent] containsString:@"+mac"]) {
>   [self.isMacVersionCheckBox setState:NSOnState];
>   } else {
>   [self.isMacVersionCheckBox setState:NSOffState];
>   }
> }
> 
> There's nothing special about this code; I see no reason why it shouldn't 
> work, but then again, this *is* programming. I'll take a look and investigate 
> some more.

Where does containsString: come from by the way? The (n)ever-useful 
documentation on my box doesn’t have it, the header file for NSString tells me 
it does exist in 10.10 or iOS8. Apart from despairing again that documentation 
doesn’t appear to be driven from the header files, is it possible you have a 
category somewhere which is now interfering in a nasty way with a new selector? 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com