// DoTest() // ----------------------------------------------------- // // static BAEResult DoTest(int subMenu) { BAEResult err; int i; err = BAE_NO_ERROR; switch (subMenu) { case TEST_MIXER_CONSTRUCTOR: { if (gMixer) { BAEMixer_Delete(gMixer); gMixer = NULL; } for (i=0; i<100; i++) { gMixer = BAEMixer_New(); if (!gMixer) { FailedTest("Couldn't allocate BAEMixer object. Exiting Test!"); return BAE_MEMORY_ERR; } BAEMixer_Delete(gMixer); gMixer = NULL; } gMixer = BAEMixer_New(); } break; case TEST_MIXER_OPEN_CLOSE: { err = TestOpenClose(); } break; case TEST_MIXER_GET_SET_MASTER_VOLUME: { err = TestGetSetMasterVolume(); } break; case TEST_MIXER_GET_SET_HARDWARE_VOLUME: { err = TestGetSetHardwareVolume(); } break; default: break; } return err; }
// BeatnikPlay() // --------------------------------------------------------------------- // // BAEResult BeatnikPlay(char *filePath, char *patchesPath) { BAEResult err; BAEMixer theMixer; short int rmf, pcm; BAEBankToken bank; theMixer = BAEMixer_New(); if (theMixer) { rmf = BAE_MAX_VOICES; pcm = 0; printf("Allocating mixer with %d voices for RMF/Midi playback\n" "and %d voices for PCM playback\n", rmf, pcm); err = BAEMixer_Open(theMixer, BAE_8K, BAE_LINEAR_INTERPOLATION, BAE_USE_16 | BAE_DISABLE_REVERB, rmf, // midi voices pcm, // pcm voices (short)((rmf+pcm)/2), TRUE); if (err == BAE_NO_ERROR) { printf("BAE memory used during idle prior to SetBankToFile: %ld\n\n", BAE_GetSizeOfMemoryUsed()); err = BAEMixer_AddBankFromFile(theMixer, (BAEPathName)patchesPath, &bank); printf("BAE memory used during idle after SetBankToFile: %ld\n\n", BAE_GetSizeOfMemoryUsed()); if (err == BAE_NO_ERROR) { err = PlayRMF(theMixer, filePath); } else { printf("playrmf: Couldn't set mixer bank file (BAE Error #%d)\n", err); } } else printf("playrmf: Couldn't open mixer (BAE Error #%d)\n", err); } else printf("playrmf: Memory error.\n"); BAEMixer_Delete(theMixer); return err; }
// DoFunction() // ----------------------------------------------------- // // static BAEResult DoFunction(int subMenu) { BAEResult err; BAE_BOOL validerr; validerr = TRUE; err = BAE_NO_ERROR; switch (subMenu) { // BAEMixer BAEMixer_New(void); case FUNC_MIXER_NEW: if (gMixer == NULL) { gMixer = BAEMixer_New(); } else { printf("Mixer already allocated\n"); validerr = FALSE; } break; // BAEResult BAEMixer_Delete(BAEMixer mixer); case FUNC_MIXER_DELETE: err = BAEMixer_Delete(gMixer); gMixer = NULL; if (gBankBlock) { free(gBankBlock); gBankBlock = NULL; } break; // BAEResult BAEMixer_IsOpen(BAEMixer mixer,BAE_BOOL *outIsOpen); case FUNC_MIXER_ISOPEN: { BAE_BOOL open; err = BAEMixer_IsOpen(gMixer, &open); printf("= %s\n", (open) ? "TRUE" : "FALSE"); } break; // BAEResult BAEMixer_Open(BAEMixer mixer,BAEQuality q,BAETerpMode t,BAEAudioModifiers am,short int maxMidiVoices,short int maxSoundVoices,short int mixLevel,BAE_BOOL engageAudio); case FUNC_MIXER_OPEN: { BAEQuality q; BAETerpMode t; BAEAudioModifiers am; long maxSongVoices, maxSoundVoices, level; BAE_BOOL engageAudio; BAE_BOOL ok; ok = FALSE; printf("\n"); while (ok == FALSE) { printf( ">>Output quality is: \n" " 0 for 8 kHz\n" " 1 for 11 kHz interpolated to 22 kHz\n" " 2 for 11 kHz\n" " 3 for 16 kHz\n" " 4 for 22 kHz\n" " 5 for 22 kHz interpolated to 44 kHz\n" " 6 for 24 kHz\n" " 7 for 32 kHz\n" " 8 for 40 kHz\n" " 9 for 44 kHz\n" " 10 for 48 kHz\n"); q = (BAEQuality)GetLong(">>Quality? "); t = BAE_LINEAR_INTERPOLATION; am = BAE_NONE; if (GetBool(">>Use stereo? (y/n) ")) { am |= BAE_USE_STEREO; } if (GetBool(">>16 bit output? (y/n) ")) { am |= BAE_USE_16; } maxSongVoices = GetLong(">>Maximum number of rendered notes playing at once? "); maxSoundVoices = GetLong(">>Maximum number of Sound objects playing at once? "); level = GetLong(">>Total number of full-scale voices before distortion (Song notes plus Sound objects)? "); engageAudio = GetBool(">>Send mixer audio output to the host device? (y/n) "); printf( ">>Open mixer with: \n" " BAEQuality = %ld\n" " maxSongVoices %ld\n" " maxSoundVoices = %ld\n" " mixLevel %ld\n", q, maxSongVoices, maxSoundVoices, level); if (GetBool(">>(y/n)? ")) { ok = TRUE; } } err = BAEMixer_Open(gMixer,q,t,am, (short int)maxSongVoices, (short int)maxSoundVoices, (short int)level, engageAudio); } break; // BAEResult BAEMixer_Close(BAEMixer mixer); case FUNC_MIXER_CLOSE: err = BAEMixer_Close(gMixer); if (gBankBlock) { free(gBankBlock); gBankBlock = NULL; } break; // BAEResult BAEMixer_GetMixerVersion(BAEMixer mixer, short int *pVersionMajor, short int *pVersionMinor, short int *pVersionSubMinor); case FUNC_MIXER_GETMIXERVERSION: { short int major, minor, sub; err = BAEMixer_GetMixerVersion(gMixer, &major, &minor, &sub); if (err == 0) { printf("= %d.%d.%d\n", major, minor, sub); } } break; // BAEResult BAEMixer_GetMaxDeviceCount(BAEMixer mixer,long *outMaxDeviceCount); case FUNC_MIXER_GETMAXDEVICECOUNT: { long output; err = BAEMixer_GetMaxDeviceCount(gMixer, &output); if (err == 0) { printf("= %d\n", output); } } break; // BAEResult BAEMixer_SetCurrentDevice(BAEMixer mixer, long deviceID,void *deviceParameter); case FUNC_MIXER_SETCURRENTDEVICE: { long device; device = GetLong("deviceID > "); err = BAEMixer_SetCurrentDevice(gMixer, device, NULL); } break; // BAEResult BAEMixer_GetCurrentDevice(BAEMixer mixer, void *deviceParameter, long *outDeviceID); case FUNC_MIXER_GETCURRENTDEVICE: { long device; err = BAEMixer_GetCurrentDevice(gMixer, NULL, &device); if (err == 0) { printf("= %ld\n", device); } } break; // BAEResult BAEMixer_GetDeviceName(BAEMixer mixer, long deviceID, char *cName, unsigned long cNameLength); case FUNC_MIXER_GETDEVICENAME: { long device; char name[512]; err = BAEMixer_GetMaxDeviceCount(gMixer, &device); if (err == 0) { printf("\n>>deviceID? (0-%ld", device); device = GetLong(") "); err = BAEMixer_GetDeviceName(gMixer, device, name, 512); if (err == 0) { printf("= %s\n", name); } } } break; // BAEResult BAEMixer_Is16BitSupported(BAEMixer mixer,BAE_BOOL *outIsSupported); case FUNC_MIXER_IS16BITSUPPORTED: { BAE_BOOL output; err = BAEMixer_Is16BitSupported(gMixer, &output); if (err == 0) { printf("= %s\n", (output) ? "TRUE" : "FALSE"); } } break; // BAEResult BAEMixer_Is8BitSupported(BAEMixer mixer,BAE_BOOL *outIsSupported); case FUNC_MIXER_IS8BITSUPPORTED: { BAE_BOOL output; err = BAEMixer_Is8BitSupported(gMixer, &output); if (err == 0) { printf("= %s\n", (output) ? "TRUE" : "FALSE"); } } break; // BAEResult BAEMixer_IsAudioEngaged(BAEMixer mixer,BAE_BOOL *outIsEngaged); case FUNC_MIXER_ISAUDIOENGAGED: { BAE_BOOL output; err = BAEMixer_IsAudioEngaged(gMixer, &output); if (err == 0) { printf("= %s\n", (output) ? "TRUE" : "FALSE"); } } break; // BAEResult BAEMixer_DisengageAudio(BAEMixer mixer); case FUNC_MIXER_DISENGAGEAUDIO: err = BAEMixer_DisengageAudio(gMixer); break; // BAEResult BAEMixer_ReengageAudio(BAEMixer mixer); case FUNC_MIXER_REENGAGEAUDIO: err = BAEMixer_ReengageAudio(gMixer); break; // BAEResult BAEMixer_IsAudioActive(BAEMixer mixer, BAE_BOOL *outIsActive); case FUNC_MIXER_ISAUDIOACTIVE: { BAE_BOOL isActive; err = BAEMixer_IsAudioActive(gMixer, &isActive); if (err == BAE_NO_ERROR) { printf("= %s\n", (isActive) ? "TRUE" : "FALSE"); } } break; // BAEResult BAEMixer_AddBankFromFile(BAEMixer mixer,BAEPathName pAudioPathName); case FUNC_MIXER_ADDBANKFROMFILE: { char filename[3072]; BAEBankToken token; if (GetLine("\n>>File path for new bank: ", filename, 3072)) { err = BAEMixer_AddBankFromFile(gMixer, (BAEPathName)filename, &token); if (err == 0) { printf("token = %d\n", (long)token); } } } break; // BAEResult BAEMixer_AddBankFromMemory(BAEMixer mixer,void * pAudioFile,unsigned long fileSize); case FUNC_MIXER_ADDBANKFROMMEMORY: { FILE *file; int err; char filename[3072]; BAEBankToken token; if (gBankBlock) { free(gBankBlock); gBankBlock = NULL; } gBankBlockLength = 0; if (GetLine("\n>>File path for new bank to be loaded into memory: ", filename, 3072)) { // get size of file, allocate a block of memory, then read entire file into memory file = fopen(filename, "rb"); if (file) { err = fseek(file, 0, SEEK_END); if (err == 0) { gBankBlockLength = ftell(file); fseek(file, 0, SEEK_SET); } gBankBlock = malloc(gBankBlockLength); if (gBankBlock) { gBankBlockLength = fread(gBankBlock, gBankBlockLength, 1, file); } fclose(file); } } if (gBankBlockLength) { err = BAEMixer_AddBankFromMemory(gMixer, gBankBlock, gBankBlockLength, &token); if (err == 0) { printf("token = %d\n", (unsigned long)token); } } } break; // BAEResult BAEMixer_UnloadBank(BAEMixer mixer); case FUNC_MIXER_UNLOADBANK: { BAEBankToken token = (BAEBankToken)GetLong(">>Bank token: "); err = BAEMixer_UnloadBank(gMixer, token); } break; // BAEResult BAEMixer_GetBankVersion(BAEMixer mixer,short int *pVersionMajor,short int *pVersionMinor,short int *pVersionSubMinor); case FUNC_MIXER_GETBANKVERSION: { short int major, minor, sub; BAEBankToken token = (BAEBankToken)GetLong(">>Bank token: "); err = BAEMixer_GetBankVersion(gMixer, token, &major, &minor, &sub); if (err == 0) { printf("= %d.%d.%d\n", major, minor, sub); } } break; // BAEResult BAEMixer_GetGroovoidNameFromBank(BAEMixer mixer,long index,char *cSongName); case FUNC_MIXER_GETGROOVOIDNAMEFROMBANK: { long which; char name[2048]; which = GetLong("\n>>which name (index)? "); err = BAEMixer_GetGroovoidNameFromBank(gMixer, which, name); printf("%s\n", name); } break; // BAEResult BAEMixer_ChangeAudioModes(BAEMixer mixer,BAEQuality q,BAETerpMode t,BAEAudioModifiers am); case FUNC_MIXER_CHANGEAUDIOMODES: { BAEQuality q; BAETerpMode t; BAEAudioModifiers am; printf("\n"); printf( ">>Output quality is: \n" " 0 for 8 kHz\n" " 1 for 11 kHz interpolated to 22 kHz\n" " 2 for 11 kHz\n" " 3 for 16 kHz\n" " 4 for 22 kHz\n" " 5 for 22 kHz interpolated to 44 kHz\n" " 6 for 24 kHz\n" " 7 for 32 kHz\n" " 8 for 40 kHz\n" " 9 for 44 kHz\n" " 10 for 48 kHz\n"); q = (BAEQuality)GetLong(">>Quality? "); t = BAE_LINEAR_INTERPOLATION; am = BAE_NONE; if (GetBool(">>Use stereo? (y/n) ")) { am |= BAE_USE_STEREO; } if (GetBool(">>16 bit output? (y/n) ")) { am |= BAE_USE_16; } err = BAEMixer_ChangeAudioModes(gMixer, q, t, am); } break; // BAEResult BAEMixer_GetQuality(BAEMixer mixer,BAEQuality *outQuality); case FUNC_MIXER_GETQUALITY: { BAEQuality output; err = BAEMixer_GetQuality(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; // BAEResult BAEMixer_GetTerpMode(BAEMixer mixer,BAETerpMode *outTerpMode); case FUNC_MIXER_GETTERPMODE: { BAETerpMode output; err = BAEMixer_GetTerpMode(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; // BAEResult BAEMixer_GetModifiers(BAEMixer mixer,BAEAudioModifiers *outMods); case FUNC_MIXER_GETMODIFIERS: { BAEAudioModifiers output; err = BAEMixer_GetModifiers(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; // BAEResult BAEMixer_ChangeSystemVoices(BAEMixer mixer,short int maxMidiVoices,short int maxSoundVoices,short int mixLevel); case FUNC_MIXER_CHANGESYSTEMVOICES: { long maxSongVoices, maxSoundVoices, mixLevel; printf("\n"); maxSongVoices = GetLong(">>Maximum number of rendered notes playing at once? "); maxSoundVoices = GetLong(">>Maximum number of Sound objects playing at once? "); mixLevel = GetLong(">>Total number of full-scale voices before distortion (Song notes plus Sound objects)? "); err = BAEMixer_ChangeSystemVoices(gMixer, (short)maxSongVoices, (short)maxSoundVoices, (short)mixLevel); } break; // BAEResult BAEMixer_GetMidiVoices(BAEMixer mixer,short int *outNumMidiVoices); case FUNC_MIXER_GETMIDIVOICES: { short int output; err = BAEMixer_GetMidiVoices(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; // BAEResult BAEMixer_GetSoundVoices(BAEMixer mixer,short int *outNumSoundVoices); case FUNC_MIXER_GETSOUNDVOICES: { short int output; err = BAEMixer_GetSoundVoices(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; // BAEResult BAEMixer_GetMixLevel(BAEMixer mixer,short int *outMixLevel); case FUNC_MIXER_GETMIXLEVEL: { short int output; err = BAEMixer_GetMixLevel(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; // BAEResult BAEMixer_GetTick(BAEMixer mixer,unsigned long *outTick); case FUNC_MIXER_GETTICK: { unsigned long output; err = BAEMixer_GetTick(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; // BAEResult BAEMixer_SetAudioLatency(BAEMixer mixer,unsigned long requestedLatency); case FUNC_MIXER_SETAUDIOLANTENCY: { unsigned long input; input = GetLong("\n>>New Latency? "); err = BAEMixer_SetAudioLatency(gMixer, input); } break; // BAEResult BAEMixer_GetAudioLatency(BAEMixer mixer,unsigned long *outLatency); case FUNC_MIXER_GETAUDIOLANTENCY: { unsigned long output; err = BAEMixer_GetAudioLatency(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; // BAEResult BAEMixer_SetMasterVolume(BAEMixer mixer,BAE_UNSIGNED_FIXED theVolume); case FUNC_MIXER_SETMASTERVOLUME: { double finput; finput = GetDouble("Master volume (1.0 norm) > "); err = BAEMixer_SetMasterVolume(gMixer, FLOAT_TO_UNSIGNED_FIXED(finput)); } break; // BAEResult BAEMixer_GetMasterVolume(BAEMixer mixer,BAE_UNSIGNED_FIXED *outVolume); case FUNC_MIXER_GETMASTERVOLUME: { BAE_UNSIGNED_FIXED output; double foutput; err = BAEMixer_GetMasterVolume(gMixer, &output); foutput = UNSIGNED_FIXED_TO_FLOAT(output); printf("= %lf\n", foutput); } break; // BAEResult BAEMixer_SetHardwareVolume(BAEMixer mixer,BAE_UNSIGNED_FIXED theVolume); case FUNC_MIXER_SETHARDWAREVOLUME: { double finput; finput = GetDouble("Hardware volume (1.0 norm) > "); err = BAEMixer_SetHardwareVolume(gMixer, FLOAT_TO_UNSIGNED_FIXED(finput)); } break; // BAEResult BAEMixer_GetHardwareVolume(BAEMixer mixer,BAE_UNSIGNED_FIXED *outVolume); case FUNC_MIXER_GETHARDWAREVOLUME: { BAE_UNSIGNED_FIXED output; double foutput; err = BAEMixer_GetHardwareVolume(gMixer, &output); foutput = UNSIGNED_FIXED_TO_FLOAT(output); printf("= %lf\n", foutput); } break; // BAEResult BAEMixer_SetMasterSoundEffectsVolume(BAEMixer mixer,BAE_UNSIGNED_FIXED theVolume); case FUNC_MIXER_SETMASTERSOUNDEFFECTSVOLUME: { double finput; finput = GetDouble("Sound effects volume (1.0 norm) > "); err = BAEMixer_SetMasterSoundEffectsVolume(gMixer, FLOAT_TO_UNSIGNED_FIXED(finput)); } break; // BAEResult BAEMixer_GetMasterSoundEffectsVolume(BAEMixer mixer,BAE_UNSIGNED_FIXED *outVolume); case FUNC_MIXER_GETMASTERSOUNDEFFECTSVOLUME: { BAE_UNSIGNED_FIXED output; double foutput; err = BAEMixer_GetMasterSoundEffectsVolume(gMixer, &output); foutput = UNSIGNED_FIXED_TO_FLOAT(output); printf("= %lf\n", foutput); } break; // BAEResult BAEMixer_GetAudioSampleFrame(BAEMixer mixer,short int *pLeft,short int *pRight,short int *outFrame); case FUNC_MIXER_GETAUDIOSAMPLEFRAME: { short int left[1024], right[1024]; short int outputSize, leftcrc, rightcrc, count; err = BAEMixer_GetAudioSampleFrame(gMixer, left, right, &outputSize); leftcrc = 0; rightcrc = 0; for (count = 0; count < outputSize; count++) { leftcrc += left[count]; rightcrc += right[count]; } printf("= frames %d, left crc %d, right crc %d\n", outputSize, leftcrc, rightcrc); } break; // BAEResult BAEMixer_GetRealtimeStatus(BAEMixer mixer,BAEAudioInfo *pStatus); case FUNC_MIXER_GETREALTIMESTATUS: { BAEAudioInfo status; short int count, voice; err = BAEMixer_GetRealtimeStatus(gMixer, &status); if (err == BAE_NO_ERROR) { printf("\nThere are %d active voices\n", status.voicesActive); printf("Type:\n"); for (count = 0; count < status.voicesActive; count++) { voice = status.voice[count]; printf("[%d] %d ", voice, status.voiceType[voice]); } printf("\nInstrument:\n"); for (count = 0; count < status.voicesActive; count++) { voice = status.voice[count]; printf("[%d] %d ", voice, status.instrument[voice]); } printf("\nMidi Volume:\n"); for (count = 0; count < status.voicesActive; count++) { voice = status.voice[count]; printf("[%d] %d ", voice, status.midiVolume[voice]); } printf("\nScaled Volume:\n"); for (count = 0; count < status.voicesActive; count++) { voice = status.voice[count]; printf("[%d] %d ", voice, status.scaledVolume[voice]); } printf("\nChannel:\n"); for (count = 0; count < status.voicesActive; count++) { voice = status.voice[count]; printf("[%d] %d ", voice, status.channel[voice]); } printf("\nMidi Note:\n"); for (count = 0; count < status.voicesActive; count++) { voice = status.voice[count]; printf("[%d] %d ", voice, status.midiNote[voice]); } printf("\nUser Reference:\n"); for (count = 0; count < status.voicesActive; count++) { voice = status.voice[count]; printf("[%d] %ld ", voice, status.userReference[voice]); } printf("\n"); } } break; // BAEResult BAEMixer_GetCPULoadInMicroseconds(BAEMixer mixer,unsigned long *outLoad); case FUNC_MIXER_GETCPULOADINMICROSECONDS: { unsigned long output; err = BAEMixer_GetCPULoadInMicroseconds(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; // BAEResult BAEMixer_GetCPULoadInPercent(BAEMixer mixer,unsigned long *outLoad); case FUNC_MIXER_GETCPULOADINPERCENT: { unsigned long output; err = BAEMixer_GetCPULoadInPercent(gMixer, &output); if (err == 0) { printf("= %ld\n", (long)output); } } break; case FUNC_MIXER_BRINGBANKTOFRONT: { BAEBankToken token; token = (BAEBankToken)GetLong("Bank token: "); err = BAEMixer_BringBankToFront(gMixer, token); } break; case FUNC_MIXER_SENDBANKTOBACK: { BAEBankToken token; token = (BAEBankToken)GetLong("Bank token: "); err = BAEMixer_SendBankToBack(gMixer, token); } break; default: err = BAE_GENERAL_BAD; break; } return err; }