static PyObject *Snd_SndNewChannel(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; OSErr _err; SndChannelPtr chan = 0; short synth; long init; PyObject* userRoutine; if (!PyArg_ParseTuple(_args, "hlO", &synth, &init, &userRoutine)) return NULL; if (userRoutine != Py_None && !PyCallable_Check(userRoutine)) { PyErr_SetString(PyExc_TypeError, "callback must be callable"); goto userRoutine__error__; } _err = SndNewChannel(&chan, synth, init, NewSndCallBackUPP(SndCh_UserRoutine)); if (_err != noErr) return PyMac_Error(_err); _res = Py_BuildValue("O&", SndCh_New, chan); if (_res != NULL && userRoutine != Py_None) { SndChannelObject *p = (SndChannelObject *)_res; p->ob_itself->userInfo = (long)p; Py_INCREF(userRoutine); p->ob_callback = userRoutine; } userRoutine__error__: ; return _res; }
void child_sound_init_mac() { OSStatus err; mac_printf("In mac child\n"); fflush(stdout); mac_printf("pid: %d\n", getpid()); fflush(stdout); //return; //g_snd_channel_ptr = 0; err = SndNewChannel(&g_snd_channel_ptr, sampledSynth, initStereo, NewSndCallBackUPP(mac_snd_callback)); mac_printf("SndNewChannel ret: %d\n", (int)err); fflush(stdout); memset(&g_snd_hdr, 0, sizeof(g_snd_hdr)); g_snd_hdr.sampleSize = 16; g_snd_hdr.numChannels = 2; g_audio_rate = 44100; g_snd_hdr.sampleRate = g_audio_rate << 16; g_snd_hdr.numFrames = 0; // will be set in mac_send_audio g_snd_hdr.encode = extSH; g_snd_hdr.baseFrequency = 0; g_snd_hdr.samplePtr = 0; set_audio_rate(g_audio_rate); mac_printf("End of child_sound_init_mac\n"); fflush(stdout); }
static BOOL SoundChannel_Init(void) { volatile QSOUND qs; qs = &QSound; ZeroMemory(qs, sizeof(QSOUND)); #if TARGET_API_MAC_CARBON qs->cb = NewSndCallBackUPP(QSoundCallback); #else qs->cb = NewSndCallBackProc(QSoundCallback); #endif if (SndNewChannel(&qs->hdl, sampledSynth, initStereo + initNoInterp + initNoDrop, qs->cb) != noErr) { return(FAILURE); } return(SUCCESS); }
void init_snd_tool(){ short i,t; SndCallBackUPP callback; for (i = 0; i < NUM_SOUNDS; i++) { if (!load_when_play[i]) { sound_handles[i] = GetResource('snd ', 20000 + i); } } callback = NewSndCallBackUPP(snd_channel_callback); for(t=0;t<4;t++){ // setup 4 sound channels SndNewChannel(&chan[t], sampledSynth, initMono + initNoDrop, callback); chan[t]->qLength = 128; } }
int BURGERCALL MADSndOpen( MADDriverRec *inMADDriver) { int err; SndChannelPtr mySndChan; // pointer to a sound channel SndCallBackUPP CallBack; CallBack = NewSndCallBackUPP(MyDoubleBackProc); err=-1; if (CallBack) { mySndChan = 0L; err = SndNewChannel(&mySndChan, sampledSynth, 0, CallBack); if (!err) { if (mySndChan) { /* Failsafe */ inMADDriver->CallBackUPP = CallBack; inMADDriver->MusicChannelPP = mySndChan; mySndChan->userInfo = (long)inMADDriver; return DBSndPlay(inMADDriver, inMADDriver->MusicChannelPP); } err = MADSoundManagerErr; } DisposeSndCallBackUPP(CallBack); /* Kill the callback */ } return err; }
static int macos_init_sound (SINT16 *b) { SndCallBackUPP cb; SndCommand cmd; report ("sound_macos: written by [email protected]\n"); sarienbuf = b; header.numChannels = 1; header.sampleSize = 16; header.sampleRate = rate22khz; header.numFrames = BUFFER_SIZE; header.encode = cmpSH; buffer[0] = malloc (BUFFER_SIZE << 1); buffer[1] = malloc (BUFFER_SIZE << 1); if (!buffer[0] || !buffer[1]) { report ("sound_macos: Out of memory allocating %d bytes\n", BUFFER_SIZE << 1); return -1; } cb = NewSndCallBackUPP (fill_sound); if (SndNewChannel (&channel, sampledSynth, initMono, cb) != noErr) { report ("sound_macos: Unable to create channel"); return -1; } cmd.cmd = callBackCmd; cmd.param2 = 0; SndDoCommand (channel, &cmd, 0); return 0; }
static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) { SndCallBackUPP callback; int sample_bits; int i; long initOptions; /* Very few conversions are required, but... */ switch (spec->format) { case AUDIO_S8: spec->format = AUDIO_U8; break; case AUDIO_U16LSB: spec->format = AUDIO_S16LSB; break; case AUDIO_U16MSB: spec->format = AUDIO_S16MSB; break; } SDL_CalculateAudioSpec(spec); /* initialize bufferCmd header */ memset (&header, 0, sizeof(header)); callback = NewSndCallBackUPP (callBackProc); sample_bits = spec->size / spec->samples / spec->channels * 8; #ifdef DEBUG_AUDIO fprintf(stderr, "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n", spec->format, spec->channels, sample_bits, spec->freq); #endif /* DEBUG_AUDIO */ header.numChannels = spec->channels; header.sampleSize = sample_bits; header.sampleRate = spec->freq << 16; header.numFrames = spec->samples; header.encode = cmpSH; /* Note that we install the 16bitLittleEndian Converter if needed. */ if ( spec->format == 0x8010 ) { header.compressionID = fixedCompression; header.format = k16BitLittleEndianFormat; } /* allocate 2 buffers */ for (i=0; i<2; i++) { buffer[i] = (UInt8*)malloc (sizeof(UInt8) * spec->size); if (buffer[i] == NULL) { SDL_OutOfMemory(); return (-1); } memset (buffer[i], 0, spec->size); } /* Create the sound manager channel */ channel = (SndChannelPtr)malloc(sizeof(*channel)); if ( channel == NULL ) { SDL_OutOfMemory(); return(-1); } if ( spec->channels >= 2 ) { initOptions = initStereo; } else { initOptions = initMono; } channel->userInfo = (long)this; channel->qLength = 128; if ( SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr ) { SDL_SetError("Unable to create audio channel"); free(channel); channel = NULL; return(-1); } /* start playback */ { SndCommand cmd; cmd.cmd = callBackCmd; cmd.param2 = 0; running = 1; SndDoCommand (channel, &cmd, 0); } return 1; }
static int SNDMGR_OpenDevice(_THIS, const char *devname, int iscapture) { SDL_AudioSpec *spec = &this->spec; SndChannelPtr channel = NULL; SndCallBackUPP callback; int sample_bits; int i; long initOptions; /* Initialize all variables that we clean on shutdown */ this->hidden = (struct SDL_PrivateAudioData *) SDL_malloc((sizeof *this->hidden)); if (this->hidden == NULL) { SDL_OutOfMemory(); return 0; } SDL_memset(this->hidden, 0, (sizeof *this->hidden)); /* !!! FIXME: iterate through format matrix... */ /* Very few conversions are required, but... */ switch (spec->format) { case AUDIO_S8: spec->format = AUDIO_U8; break; case AUDIO_U16LSB: spec->format = AUDIO_S16LSB; break; case AUDIO_U16MSB: spec->format = AUDIO_S16MSB; break; case AUDIO_F32LSB: spec->format = AUDIO_F32MSB; break; } SDL_CalculateAudioSpec(&this->spec); /* initialize bufferCmd header */ SDL_memset(&header, 0, sizeof(header)); callback = (SndCallBackUPP) NewSndCallBackUPP(callBackProc); sample_bits = spec->size / spec->samples / spec->channels * 8; #ifdef DEBUG_AUDIO fprintf(stderr, "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n", spec->format, spec->channels, sample_bits, spec->freq); #endif /* DEBUG_AUDIO */ header.numChannels = spec->channels; header.sampleSize = sample_bits; header.sampleRate = spec->freq << 16; header.numFrames = spec->samples; header.encode = cmpSH; /* Note that we install the 16bitLittleEndian Converter if needed. */ if (spec->format == AUDIO_S16LSB) { header.compressionID = fixedCompression; header.format = k16BitLittleEndianFormat; } else if (spec->format == AUDIO_S32MSB) { header.compressionID = fixedCompression; header.format = k32BitFormat; } else if (spec->format == AUDIO_S32LSB) { header.compressionID = fixedCompression; header.format = k32BitLittleEndianFormat; } else if (spec->format == AUDIO_F32MSB) { header.compressionID = fixedCompression; header.format = kFloat32Format; } /* allocate 2 buffers */ for (i = 0; i < 2; i++) { buffer[i] = (UInt8 *) SDL_malloc(sizeof(UInt8) * spec->size); if (buffer[i] == NULL) { SNDMGR_CloseDevice(this); SDL_OutOfMemory(); return 0; } SDL_memset(buffer[i], 0, spec->size); } /* Create the sound manager channel */ channel = (SndChannelPtr) SDL_malloc(sizeof(*channel)); if (channel == NULL) { SNDMGR_CloseDevice(this); SDL_OutOfMemory(); return 0; } this->hidden->channel = channel; if (spec->channels >= 2) { initOptions = initStereo; } else { initOptions = initMono; } channel->userInfo = (long) this; channel->qLength = 128; if (SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr) { SNDMGR_CloseDevice(this); SDL_SetError("Unable to create audio channel"); return 0; } /* start playback */ { SndCommand cmd; cmd.cmd = callBackCmd; cmd.param2 = 0; running = 1; SndDoCommand(channel, &cmd, 0); } return 1; }
NAudioUnit::NAudioUnit() { int i; OSStatus err; _bInitialized = _bRunning = false; _iLastFrameNr = _iFrameRepeat = 0; _pBuffers[0] = _pBuffers[1] = NULL; _pTempBuf = NULL; // setup sound manager structures SndCallBackUPP callBackUPP = NewSndCallBackUPP(SMCallBackFunc); _sndChannel = NULL; err = SndNewChannel(&_sndChannel, sampledSynth, initMono, callBackUPP); if(err != noErr) { _sndChannel = NULL; NotifyUser(kSoundErrStringNr, kSoundErrStringNr + 1, kOKButtonStringNr); } memset(&_eshHeader, 0, sizeof(_eshHeader)); _eshHeader.numChannels = 1; _eshHeader.encode = extSH; _eshHeader.baseFrequency = kMiddleC; _eshHeader.sampleSize = 16; // allocate sample memory for(i=0; i<4; i++) _pSquares[i] = new double[kSampleSize]; _pTriangle = new double[kSampleSize]; _pNoise = new double[kNoiseSampleSize]; // generate default samples GenSquare16(_pSquares[0], 87.5); GenSquare16(_pSquares[1], 75.0); GenSquare16(_pSquares[2], 50.0); GenSquare16(_pSquares[3], 25.0); GenTriangle16(_pTriangle); GenNoise16(_pNoise); // setup tables _iDMCMaxAmp = 4; _iDMCMinAmp = -4; _fNoiseStepTab[ 0] = 1.0/1.0001831390; _fNoiseStepTab[ 1] = 1.0/1.0001526112; _fNoiseStepTab[ 2] = 1.0/1.0002075626; _fNoiseStepTab[ 3] = 1.0/1.0002197749; _fNoiseStepTab[ 4] = 1.0/1.5772803851; _fNoiseStepTab[ 5] = 1.0/2.3661293817; _fNoiseStepTab[ 6] = 1.0/3.1545304016; _fNoiseStepTab[ 7] = 1.0/3.9398821691; _fNoiseStepTab[ 8] = 1.0/4.9777777778; _fNoiseStepTab[ 9] = 1.0/6.2596469779; _fNoiseStepTab[10] = 1.0/9.3610970036; _fNoiseStepTab[11] = 1.0/12.5176200936; _fNoiseStepTab[12] = 1.0/18.7746371276; _fNoiseStepTab[13] = 1.0/25.0328495034; _fNoiseStepTab[14] = 1.0/50.0529531568; _fNoiseStepTab[15] = 1.0/50.4640657084; _iTimeConvTab[ 0] = 5; _iTimeConvTab[ 1] = 127; _iTimeConvTab[ 2] = 10; _iTimeConvTab[ 3] = 1; _iTimeConvTab[ 4] = 20; _iTimeConvTab[ 5] = 2; _iTimeConvTab[ 6] = 40; _iTimeConvTab[ 7] = 3; _iTimeConvTab[ 8] = 80; _iTimeConvTab[ 9] = 4; _iTimeConvTab[10] = 30; _iTimeConvTab[11] = 5; _iTimeConvTab[12] = 7; _iTimeConvTab[13] = 6; _iTimeConvTab[14] = 14; _iTimeConvTab[15] = 7; _iTimeConvTab[16] = 6; _iTimeConvTab[17] = 8; _iTimeConvTab[18] = 12; _iTimeConvTab[19] = 9; _iTimeConvTab[20] = 24; _iTimeConvTab[21] = 10; _iTimeConvTab[22] = 48; _iTimeConvTab[23] = 11; _iTimeConvTab[24] = 96; _iTimeConvTab[25] = 12; _iTimeConvTab[26] = 36; _iTimeConvTab[27] = 13; _iTimeConvTab[28] = 8; _iTimeConvTab[29] = 14; _iTimeConvTab[30] = 16; _iTimeConvTab[31] = 15; for(i=0; i<16; i++) _fVolTab[i] = sin((1.5707963435/15.0)*((double)i)); // get volume from prefs UpdateVolume(); // initialize playback Initialize(kAPU_44kHz, 1); }
int audio_open(snd_node *n, long *f) { buffer_state *data = (buffer_state *)malloc(sizeof(buffer_state)); n->u.audio.descriptor = (void *)data; OSErr err; Fixed sampleRateFixed; data->frameSize = snd_bytes_per_frame(n); data->bufferSize = (int) (n->format.srate * (double)data->frameSize); if (n->u.audio.latency > 0.0) data->bufferSize = (int)(n->format.srate * n->u.audio.latency) * data->frameSize; /* Calculate sample rate as an unsigned fixed-point number */ if (n->format.srate > 65535.0 || n->format.srate < 1.0) sampleRateFixed = 0xAC440000; /* Fixed for 44100 */ else { unsigned short numerator = (unsigned short)n->format.srate; unsigned short denominator = (unsigned short)(65536.0*(n->format.srate - numerator)); sampleRateFixed = (numerator << 16) | denominator; } /* Open device for recording or playback, depending on mode selected */ if (n->write_flag == SND_READ) { /* recording */ short gainControl = 0; /* off */ short numChannels = n->format.channels; short continuousRecording = 1; /* on */ short playthroughVolume = 0; /* off */ OSType quality = 'cd '; short sampleSize = 16; short twos = 0; /* i.e. signed */ OSType compression = 'NONE'; SoundInfoList infoList; int len, i, x, y, z; short selected = 0; char *device; char *input; char **buffer; char oneInput[256]; char *deviceData; data->recording = 1; len = strlen(n->u.audio.devicename); device = new char[len+1]; input = new char[len+1]; strcpy(device, n->u.audio.devicename); input[0] = 0; for(i=0; i<len; i++) { if (device[i] == '\n') { device[i] = 0; strcpy(input, &device[i+1]); i = len; } } err = SPBOpenDevice(c2pstr(device), siWritePermission, &data->refnum); if (err) return !SND_SUCCESS; SPBGetDeviceInfo (data->refnum, siInputAvailable, &infoList); SPBGetDeviceInfo (data->refnum, siInputSourceNames, &buffer); deviceData = buffer[0] + 2; for(int x=0; x<infoList.count; x++) { int y = *deviceData++; z = 0; while(y) { oneInput[z++] = *deviceData++; y--; } oneInput[z] = 0; if (!strcmp(oneInput, input)) selected = x; } selected++; SPBSetDeviceInfo (data->refnum, siInputSource, &selected); SPBSetDeviceInfo(data->refnum, 'qual', &quality); SPBSetDeviceInfo(data->refnum, 'agc ', &gainControl); SPBSetDeviceInfo(data->refnum, 'srat', &sampleRateFixed); SPBSetDeviceInfo(data->refnum, 'plth', &playthroughVolume); err = SPBSetDeviceInfo(data->refnum, 'ssiz', &sampleSize); if (err) return !SND_SUCCESS; err = SPBSetDeviceInfo(data->refnum, 'chan', &numChannels); if (err) return !SND_SUCCESS; err = SPBSetDeviceInfo(data->refnum, 'cont', &continuousRecording); if (err) return !SND_SUCCESS; err = SPBSetDeviceInfo(data->refnum, 'twos', &twos); if (err) return !SND_SUCCESS; err = SPBSetDeviceInfo(data->refnum, 'comp', &compression); if (err) return !SND_SUCCESS; data->recBuffer = (char *)malloc(data->bufferSize); data->recqStart = 0; data->recqEnd = 0; data->starved = 0; data->params.inRefNum = data->refnum; data->params.count = 0; /* data->bufferSize; /* bytes to record */ data->params.milliseconds = 0; /* param will be ignored; use count */ data->params.bufferLength = 0; /* ignore buffer */ data->params.bufferPtr = NULL; /* ignore buffer */ data->params.completionRoutine = NULL; data->params.userLong = (long)data; data->params.unused1 = 0; data->params.interruptRoutine = NewSIInterruptUPP(recordingCallback); err = SPBRecord(&data->params, true); if (err) return !SND_SUCCESS; } else { /* playback */ data->recording = 0; data->chan = NULL; //////////////////////// err = SndNewChannel(&data->chan, sampledSynth, 0, NULL); if (err) return !SND_SUCCESS; data->buffer = (char *)malloc(data->bufferSize); data->nextBufferSize = data->bufferSize * 3; data->nextBuffer = (char *)malloc(data->nextBufferSize); if (!data->buffer || !data->nextBuffer) return !SND_SUCCESS; data->chan->callBack = NewSndCallBackUPP(playbackCallback); data->header.samplePtr = data->buffer; data->header.numChannels = n->format.channels; data->header.sampleRate = sampleRateFixed; data->header.loopStart = 0; data->header.loopEnd = 0; data->header.encode = cmpSH; data->header.baseFrequency = kMiddleC; // data->header.AIFFSampleRate = 0; -- this parameter is unused data->header.markerChunk = NULL; data->header.format = kSoundNotCompressed; data->header.futureUse2 = NULL; data->header.stateVars = NULL; data->header.leftOverSamples = NULL; data->header.compressionID = 0; data->header.packetSize = 0; data->header.snthID = 0; data->header.sampleSize = 16; data->header.sampleArea[0] = 0; data->playCmd.cmd = bufferCmd; data->playCmd.param1 = 0; //unused data->playCmd.param2 = (long)&data->header; data->callCmd.cmd = callBackCmd; data->callCmd.param1 = 0; data->callCmd.param2 = (long)data; data->curBuffer = 0; data->curSize = 0; data->firstTime = 1; data->finished = 0; data->busy = 0; data->flushing = 0; } return SND_SUCCESS; }