/* Copyright (c) 2019 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #include "nativeaudio/AudioOut.h" #include "nativeaudio/AudioOut_private.h" #include #include #include #include AudioOut_sampleFormat AudioOut_getHostFormat(void) { return g_AudioOut_hostFormat; } AudioOut_sampleFormat AudioOut_getTransportFormat(void) { return g_AudioOut_transportFormat; } void AudioOut_setFileOutput(const char * filePath) { if (g_AudioOut_outputFileHandle != 0) { close(g_AudioOut_outputFileHandle); } g_AudioOut_outputFileHandle = open(filePath, O_CREAT | O_WRONLY | O_TRUNC, 0777); } void AudioOut_setTransportFormat(AudioOut_sampleFormat format) { if (format.channelCount == 0 || format.channelCount > 2) { #ifdef DEBUG fprintf(stderr, "Error: Requested sample format specifies %u channels; must be between 1 and 2\n", format.channelCount); #endif abort(); } if (format.sampleRate == 0) { #ifdef DEBUG fprintf(stderr, "Error: Requested sample format specifies invalid sampleRate of 0\n"); #endif abort(); } bool wasPlaying = g_AudioOut_outputActive; if (wasPlaying) { AudioOut_stopOutput(); } g_AudioOut_transportFormat = format; g_AudioOut_resampleState = initAudioResampleState(); if (wasPlaying) { AudioOut_startOutput(g_AudioOut_outputCallback, g_AudioOut_outputContext); } }