Fixed freeaudios coreaudio device removing use of deprecated interface
authorSimon Armstrong <nitrologic@gmail.com>
Wed, 14 Oct 2015 05:39:43 +0000 (18:39 +1300)
committerSimon Armstrong <nitrologic@gmail.com>
Wed, 14 Oct 2015 05:39:43 +0000 (18:39 +1300)
mod/pub.mod/freeaudio.mod/coreaudiodevice.cpp
mod/pub.mod/freeaudio.mod/freeaudio.bmx

index 5d67f53725184f76667ed05bc933af94ab26a989..d1930fb72e6d245d19d217763b02d0926acaab61 100644 (file)
-// apple core audio device
-
-#include "freeaudio.h"
-
-#ifdef __APPLE__
-
-#include <CoreServices/CoreServices.h>
-#include <AudioUnit/AudioUnit.h>
-#include <CoreAudio/CoreAudio.h>
-#include <AudioToolbox/AudioToolbox.h>
-
-extern "C" audiodevice *OpenCoreAudioDevice();
-
-OSStatus FeedSound(void *ref,AudioUnitRenderActionFlags *flags,const AudioTimeStamp *time,UInt32 bus,UInt32 frames,AudioBufferList *data);
-
-struct coreaudio:audiodevice{
-       AudioUnit                               out;
-       AudioConverterRef               conv;
-       AURenderCallbackStruct  callback;
-       short                                   *buffer;
-       int                                     tcount;
-
-       int reset(){
-               int     res;
-               
-               mix=new mixer(8192);
-               mix->freq=44100;
-               mix->channels=2;
-
-               out=0;
-               res=initoutput();
-               if (res) return res;
-               
-               callback.inputProc=FeedSound;
-               callback.inputProcRefCon=this;
-
-               buffer=new short[8192];
-               
-               res=AudioUnitSetProperty(out,kAudioUnitProperty_SetRenderCallback,kAudioUnitScope_Input,0,&callback,sizeof(callback));
-               if (res) return res;            
-               
-               res=AudioOutputUnitStart(out);
-               if (res) return res;                    
-                       
-               return 0;
-       }
-
-       int close(){
-               int     res;
-
-               if (out){
-                       res=AudioOutputUnitStop(out);
-                       if (res) return res;
-                       out=0;
-               }
-               return 0;
-       }
-
-       int initoutput(){
-               ComponentDescription    desc;  
-               Component                               comp;
-               OSStatus                                err;
-               UInt32                                  size;
-               Boolean                                 canwrite;
-               
-               AudioStreamBasicDescription     inputdesc,outputdesc;
-
-               desc.componentType=kAudioUnitType_Output;
-               desc.componentSubType=kAudioUnitSubType_DefaultOutput;
-               desc.componentManufacturer=kAudioUnitManufacturer_Apple;
-               desc.componentFlags=0;
-               desc.componentFlagsMask=0;
-
-               comp=FindNextComponent(NULL,&desc);if (comp==NULL) return -1;
-               err=OpenAComponent(comp,&out);if (err) return err;                              
-               err=AudioUnitInitialize(out);if (err) return err;
-               
-               err=AudioUnitGetPropertyInfo(out,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Output,0,&size,&canwrite);
-               if (err) return err;
-
-               err=AudioUnitGetProperty(out,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Input,0,&outputdesc,&size);
-               if (err) return err;            
-               
-//             dumpdesc(&outputdesc);
-               
-               inputdesc.mSampleRate=44100.0;
-               inputdesc.mFormatID='lpcm';
-#if __BIG_ENDIAN__
-               inputdesc.mFormatFlags=0x0e;
-#else
-               inputdesc.mFormatFlags=0x0c;
-#endif
-               inputdesc.mBytesPerPacket=4;
-               inputdesc.mFramesPerPacket=1;
-               inputdesc.mBytesPerFrame=4;
-               inputdesc.mChannelsPerFrame=2;
-               inputdesc.mBitsPerChannel=16;
-               inputdesc.mReserved=0;
-
-//             dumpdesc(&inputdesc);
-               
-               err=AudioConverterNew(&inputdesc,&outputdesc,&conv);
-               if (err) {
-//                     printf("AudioConvertNew failed %.*s\n",4,(char*)&err);
-                       return err;
-               }
-       
-               return err;
-       }
-
-       int read(AudioConverterRef conv,UInt32 *count,AudioBufferList *blist,AudioStreamPacketDescription **outdesc){
-               if (*count>4096) *count=4096;
-//             printf("ac read count=%d\n",*count);fflush(stdout);
-               mix->mix16(buffer,*count*2);
-               blist->mBuffers[0].mData=buffer;
-               blist->mBuffers[0].mDataByteSize=*count*4;
-               return 0;
-       }
-};
-
-OSStatus Feed(AudioConverterRef conv,UInt32 *count,AudioBufferList *blist,AudioStreamPacketDescription **outdesc,void *ref){
-       coreaudio       *audio;
-       audio=(coreaudio*)ref;
-       return audio->read(conv,count,blist,outdesc);
-}
-
-OSStatus FeedSound(void *ref,AudioUnitRenderActionFlags *flags,const AudioTimeStamp *time,UInt32 bus,UInt32 count,AudioBufferList *blist){
-       coreaudio       *audio;
-       audio=(coreaudio*)ref;
-       return AudioConverterFillComplexBuffer(audio->conv,Feed,ref,&count,blist,0);
-}
-
-audiodevice *OpenCoreAudioDevice(){
-       return new coreaudio();
-}
-
-#endif
+// apple core audio device\r
+\r
+#include "freeaudio.h"\r
+\r
+#ifdef __APPLE__\r
+\r
+#include <AudioToolbox/AudioToolbox.h>\r
+\r
+extern "C" audiodevice *OpenCoreAudioDevice();\r
+\r
+OSStatus FeedSound(void *ref,AudioUnitRenderActionFlags *flags,const AudioTimeStamp *time,UInt32 bus,UInt32 frames,AudioBufferList *data);\r
+\r
+struct coreaudio:audiodevice{\r
+       AudioUnit                               out;\r
+       AudioConverterRef               conv;\r
+       AURenderCallbackStruct  callback;\r
+       short                                   *buffer;\r
+       int                                     tcount;\r
+\r
+       int reset(){\r
+               int     res;\r
+               \r
+               mix=new mixer(8192);\r
+               mix->freq=44100;\r
+               mix->channels=2;\r
+\r
+               out=0;\r
+               res=initoutput();\r
+               if (res) return res;\r
+               \r
+               callback.inputProc=FeedSound;\r
+               callback.inputProcRefCon=this;\r
+\r
+               buffer=new short[8192];\r
+               \r
+               res=AudioUnitSetProperty(out,kAudioUnitProperty_SetRenderCallback,kAudioUnitScope_Input,0,&callback,sizeof(callback));\r
+               if (res) return res;            \r
+               \r
+               res=AudioOutputUnitStart(out);\r
+               if (res) return res;                    \r
+                       \r
+               return 0;\r
+       }\r
+\r
+       int close(){\r
+               int     res;\r
+\r
+               if (out){\r
+                       res=AudioOutputUnitStop(out);\r
+                       if (res) return res;\r
+                       out=0;\r
+               }\r
+               return 0;\r
+       }\r
+\r
+       int initoutput(){\r
+               AudioComponentDescription desc;  \r
+               AudioComponent comp;\r
+               OSStatus err;\r
+               UInt32 size;\r
+               Boolean canwrite;\r
+               \r
+               AudioStreamBasicDescription     inputdesc,outputdesc;\r
+\r
+               desc.componentType=kAudioUnitType_Output;\r
+               desc.componentSubType=kAudioUnitSubType_DefaultOutput;\r
+               desc.componentManufacturer=kAudioUnitManufacturer_Apple;\r
+               desc.componentFlags=0;\r
+               desc.componentFlagsMask=0;\r
+\r
+               comp=AudioComponentFindNext(NULL,&desc);\r
+               if (comp==NULL) return -1;\r
+\r
+               err= AudioComponentInstanceNew(comp,&out);\r
+               if (err) return err;                            \r
+\r
+               err=AudioUnitInitialize(out);if (err) return err;\r
+               \r
+               err=AudioUnitGetPropertyInfo(out,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Output,0,&size,&canwrite);\r
+               if (err) return err;\r
+\r
+               err=AudioUnitGetProperty(out,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Input,0,&outputdesc,&size);\r
+               if (err) return err;            \r
+               \r
+//             dumpdesc(&outputdesc);\r
+               \r
+               inputdesc.mSampleRate=44100.0;\r
+               inputdesc.mFormatID='lpcm';\r
+#if __BIG_ENDIAN__\r
+               inputdesc.mFormatFlags=0x0e;\r
+#else\r
+               inputdesc.mFormatFlags=0x0c;\r
+#endif\r
+               inputdesc.mBytesPerPacket=4;\r
+               inputdesc.mFramesPerPacket=1;\r
+               inputdesc.mBytesPerFrame=4;\r
+               inputdesc.mChannelsPerFrame=2;\r
+               inputdesc.mBitsPerChannel=16;\r
+               inputdesc.mReserved=0;\r
+\r
+//             dumpdesc(&inputdesc);\r
+               \r
+               err=AudioConverterNew(&inputdesc,&outputdesc,&conv);\r
+               if (err) {\r
+//                     printf("AudioConvertNew failed %.*s\n",4,(char*)&err);\r
+                       return err;\r
+               }\r
+\r
+               return err;\r
+       }\r
+\r
+       int read(AudioConverterRef conv,UInt32 *count,AudioBufferList *blist,AudioStreamPacketDescription **outdesc){\r
+               if (*count>4096) *count=4096;\r
+//             printf("ac read count=%d\n",*count);fflush(stdout);\r
+               mix->mix16(buffer,*count*2);\r
+               blist->mBuffers[0].mData=buffer;\r
+               blist->mBuffers[0].mDataByteSize=*count*4;\r
+               return 0;\r
+       }\r
+};\r
+\r
+OSStatus Feed(AudioConverterRef conv,UInt32 *count,AudioBufferList *blist,AudioStreamPacketDescription **outdesc,void *ref){\r
+       coreaudio       *audio;\r
+       audio=(coreaudio*)ref;\r
+       return audio->read(conv,count,blist,outdesc);\r
+}\r
+\r
+OSStatus FeedSound(void *ref,AudioUnitRenderActionFlags *flags,const AudioTimeStamp *time,UInt32 bus,UInt32 count,AudioBufferList *blist){\r
+       coreaudio       *audio;\r
+       audio=(coreaudio*)ref;\r
+       return AudioConverterFillComplexBuffer(audio->conv,Feed,ref,&count,blist,0);\r
+}\r
+\r
+audiodevice *OpenCoreAudioDevice(){\r
+       return new coreaudio();\r
+}\r
+\r
+#endif\r
index 5dd5e9abad1f1ea38340754fb690d108b5165d62..c0f8ab2bdc72d047d72df4702b2c21733b60efc3 100644 (file)
-
-Module Pub.FreeAudio
-
-ModuleInfo "Version: 1.22"
-ModuleInfo "Author: Simon Armstrong"
-ModuleInfo "License: zlib/libpng"
-ModuleInfo "Copyright: Blitz Research Ltd"
-ModuleInfo "Modserver: BRL"
-
-ModuleInfo "History: 1.22 Release"
-ModuleInfo "History: Fixed leak with sound recycling"
-ModuleInfo "History: 1.21 Release"
-ModuleInfo "History: Fixed reference counting for brl.freeaudioaudio"
-ModuleInfo "History: 1.20 Release"
-ModuleInfo "History: Removed duplication of sample memory"
-ModuleInfo "History: 1.19 Release"
-ModuleInfo "History: Added DirectSound mode"
-ModuleInfo "History: 1.18 Release"
-ModuleInfo "History: added fa_ChannelPosition for live sample generation"
-ModuleInfo "History: 1.17 Release"
-ModuleInfo "History: added check for windows playback position overflow"
-ModuleInfo "History: 1.15 Release"
-ModuleInfo "History: added low latency windows98 fix"
-ModuleInfo "History: 1.14 Release"
-ModuleInfo "History: fixed 1.13 recycling of stopped channels fix"
-ModuleInfo "History: 1.13 Release"
-ModuleInfo "History: fixed recycling of stopped channels"
-ModuleInfo "History: 1.12 Release"
-ModuleInfo "History: Uses linear interpolation for improved fidelity at low rates"
-ModuleInfo "History: 1.11 Release"
-ModuleInfo "History: Fixed freepool sounds Not resetting parameters - thanks To Fetze"
-ModuleInfo "History: 1.10 Release"
-ModuleInfo "History: Added ALSA support for Linux courtesy Craig Kiesau"
-ModuleInfo "History: 1.09 Release"
-ModuleInfo "History: Improved channel playback timing"
-ModuleInfo "History: 1.08 Release"
-ModuleInfo "History: Fixed memory leak in fa_FreeSound()"
-ModuleInfo "History: 1.07 Release"
-ModuleInfo "History: Removed output transitions for queued/paused sounds"
-ModuleInfo "History: 1.06 Release"
-ModuleInfo "History: Windows device error now silently fails"
-ModuleInfo "History: 1.05 Release"
-ModuleInfo "History: Linux version now opens audio device on second thread"
-ModuleInfo "History: 1.04 Release"
-ModuleInfo "History: Removed Linux debug output"
-
-Import "freeaudio.cpp"
-Import "freeaudioglue.cpp"
-
-?Win32
-Import "dsounddevice.cpp"
-Import "mmdevice.cpp"
-Extern "C"
-Function OpenMultiMediaDevice()
-Function OpenDirectSoundDevice()
-End Extern
-?MacOS
-Import "-framework AudioUnit"
-Import "-framework AudioToolbox"
-Import "coreaudiodevice.cpp"
-Extern
-Function OpenCoreAudioDevice()
-End Extern
-?Linux
-'Import "-lasound"
-'Import "alsadevice.cpp"
-Import "ossdevice.cpp"
-Extern "C"
-Function OpenOSSDevice()
-'Function OpenALSADevice()
-End Extern
-?
-
-Extern
-
-Const FA_CHANNELSTATUS_FREE=0
-Const FA_CHANNELSTATUS_STOPPED=1
-Const FA_CHANNELSTATUS_SINGLESHOT=2
-Const FA_CHANNELSTATUS_LOOPING=4
-Const FA_CHANNELSTATUS_STREAMING=8
-Const FA_CHANNELSTATUS_PAUSED=16
-
-Function fa_Reset( audiodevice )
-Function fa_Close()
-Function fa_CreateSound( length,bits,channels,hertz,samples:Byte Ptr=Null,looping=False )
-Function fa_WriteSound( sound,samples:Byte Ptr,length ) 'length really neceesary?
-Function fa_FreeSound( sound )
-Function fa_AllocChannel()
-Function fa_FreeChannel( channel )
-Function fa_PlaySound( sound,paused_flag,channel )
-
-Function fa_StopChannel( channel )
-Function fa_ChannelStatus( channel )
-Function fa_ChannelPosition( channel )
-
-Function fa_SetChannelPaused( channel,paused )
-Function fa_SetChannelVolume( channel,volume# )
-Function fa_SetChannelRate( channel,pitch# )
-Function fa_SetChannelPan( channel,pan# )
-Function fa_SetChannelDepth( channel,depth# )
-
-End Extern
-
-Function fa_Init( deviceid )
-       Local device
-?Win32
-       If deviceid
-               device=OpenDirectSoundDevice()
-       Else
-               device=OpenMultiMediaDevice()
-       EndIf
-?Linux
-       Select deviceid
-               Case 0
-                       device=OpenOSSDevice()
-'              Case 1
-'                      device=OpenALSADevice()
-       EndSelect
-?MacOS
-       device=OpenCoreAudioDevice()
-?
-       Local res=-1
-       If device res=fa_Reset(device)
-       Return res
-End Function   
+\r
+Module Pub.FreeAudio\r
+\r
+ModuleInfo "Version: 1.23"\r
+ModuleInfo "Author: Simon Armstrong"\r
+ModuleInfo "License: zlib/libpng"\r
+ModuleInfo "Copyright: Blitz Research Ltd"\r
+ModuleInfo "Modserver: BRL"\r
+\r
+ModuleInfo "History: 1.23 Release"\r
+ModuleInfo "History: Updated OS X coreaudio to not use deprecated API"\r
+ModuleInfo "History: 1.22 Release"\r
+ModuleInfo "History: Fixed leak with sound recycling"\r
+ModuleInfo "History: 1.21 Release"\r
+ModuleInfo "History: Fixed reference counting for brl.freeaudioaudio"\r
+ModuleInfo "History: 1.20 Release"\r
+ModuleInfo "History: Removed duplication of sample memory"\r
+ModuleInfo "History: 1.19 Release"\r
+ModuleInfo "History: Added DirectSound mode"\r
+ModuleInfo "History: 1.18 Release"\r
+ModuleInfo "History: added fa_ChannelPosition for live sample generation"\r
+ModuleInfo "History: 1.17 Release"\r
+ModuleInfo "History: added check for windows playback position overflow"\r
+ModuleInfo "History: 1.15 Release"\r
+ModuleInfo "History: added low latency windows98 fix"\r
+ModuleInfo "History: 1.14 Release"\r
+ModuleInfo "History: fixed 1.13 recycling of stopped channels fix"\r
+ModuleInfo "History: 1.13 Release"\r
+ModuleInfo "History: fixed recycling of stopped channels"\r
+ModuleInfo "History: 1.12 Release"\r
+ModuleInfo "History: Uses linear interpolation for improved fidelity at low rates"\r
+ModuleInfo "History: 1.11 Release"\r
+ModuleInfo "History: Fixed freepool sounds Not resetting parameters - thanks To Fetze"\r
+ModuleInfo "History: 1.10 Release"\r
+ModuleInfo "History: Added ALSA support for Linux courtesy Craig Kiesau"\r
+ModuleInfo "History: 1.09 Release"\r
+ModuleInfo "History: Improved channel playback timing"\r
+ModuleInfo "History: 1.08 Release"\r
+ModuleInfo "History: Fixed memory leak in fa_FreeSound()"\r
+ModuleInfo "History: 1.07 Release"\r
+ModuleInfo "History: Removed output transitions for queued/paused sounds"\r
+ModuleInfo "History: 1.06 Release"\r
+ModuleInfo "History: Windows device error now silently fails"\r
+ModuleInfo "History: 1.05 Release"\r
+ModuleInfo "History: Linux version now opens audio device on second thread"\r
+ModuleInfo "History: 1.04 Release"\r
+ModuleInfo "History: Removed Linux debug output"\r
+\r
+Import "freeaudio.cpp"\r
+Import "freeaudioglue.cpp"\r
+\r
+?Win32\r
+Import "dsounddevice.cpp"\r
+Import "mmdevice.cpp"\r
+Extern "C"\r
+Function OpenMultiMediaDevice()\r
+Function OpenDirectSoundDevice()\r
+End Extern\r
+?MacOS\r
+Import "-framework CoreAudio"\r
+Import "-framework AudioUnit"\r
+Import "-framework AudioToolbox"\r
+Import "coreaudiodevice.cpp"\r
+Extern\r
+Function OpenCoreAudioDevice()\r
+End Extern\r
+?Linux\r
+'Import "-lasound"\r
+'Import "alsadevice.cpp"\r
+Import "ossdevice.cpp"\r
+Extern "C"\r
+Function OpenOSSDevice()\r
+'Function OpenALSADevice()\r
+End Extern\r
+?\r
+\r
+Extern\r
+\r
+Const FA_CHANNELSTATUS_FREE=0\r
+Const FA_CHANNELSTATUS_STOPPED=1\r
+Const FA_CHANNELSTATUS_SINGLESHOT=2\r
+Const FA_CHANNELSTATUS_LOOPING=4\r
+Const FA_CHANNELSTATUS_STREAMING=8\r
+Const FA_CHANNELSTATUS_PAUSED=16\r
+\r
+Function fa_Reset( audiodevice )\r
+Function fa_Close()\r
+Function fa_CreateSound( length,bits,channels,hertz,samples:Byte Ptr=Null,looping=False )\r
+Function fa_WriteSound( sound,samples:Byte Ptr,length ) 'length really neceesary?\r
+Function fa_FreeSound( sound )\r
+Function fa_AllocChannel()\r
+Function fa_FreeChannel( channel )\r
+Function fa_PlaySound( sound,paused_flag,channel )\r
+\r
+Function fa_StopChannel( channel )\r
+Function fa_ChannelStatus( channel )\r
+Function fa_ChannelPosition( channel )\r
+\r
+Function fa_SetChannelPaused( channel,paused )\r
+Function fa_SetChannelVolume( channel,volume# )\r
+Function fa_SetChannelRate( channel,pitch# )\r
+Function fa_SetChannelPan( channel,pan# )\r
+Function fa_SetChannelDepth( channel,depth# )\r
+\r
+End Extern\r
+\r
+Function fa_Init( deviceid )\r
+       Local device\r
+?Win32\r
+       If deviceid\r
+               device=OpenDirectSoundDevice()\r
+       Else\r
+               device=OpenMultiMediaDevice()\r
+       EndIf\r
+?Linux\r
+       Select deviceid\r
+               Case 0\r
+                       device=OpenOSSDevice()\r
+'              Case 1\r
+'                      device=OpenALSADevice()\r
+       EndSelect\r
+?MacOS\r
+       device=OpenCoreAudioDevice()\r
+?\r
+       Local res=-1\r
+       If device res=fa_Reset(device)\r
+       Return res\r
+End Function   \r