]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - osx_writer.c
osx_write: fix mono streams
[paraslash.git] / osx_writer.c
index 9ea7ad454aafce0588a00a33f4122914e65f45ee..54a1acd1e98e3c3ce597982cf7f05d56842e698b 100644 (file)
@@ -50,6 +50,8 @@ struct private_osx_writer_data {
        sem_t *semaphore;
        osx_buffer *from; /* Current buffers */
        osx_buffer *to;
+       unsigned samplerate;
+       unsigned channels;
 };
 
 
@@ -181,6 +183,8 @@ static int osx_writer_open(struct writer_node *wn)
        AudioStreamBasicDescription format;
        char s[10];
        int m, ret;
+       struct writer_node_group *wng = wn->wng;
+       struct osx_write_args_info *conf = wn->conf;
 
        wn->private_data = powd;
        /* where did that default audio output go? */
@@ -209,19 +213,25 @@ static int osx_writer_open(struct writer_node *wn)
         * AND you want the DefaultOutputUnit to do any format conversions
         * necessary from your format to the device's format.
         */
-       format.mSampleRate = 44100.0; /* The sample rate of the audio stream */
+       if (!conf->samplerate_given && wng->samplerate)
+               powd->samplerate = *wng->samplerate;
+       else
+               powd->samplerate = conf->samplerate_arg;
+       format.mSampleRate = powd->samplerate;
        /* The specific encoding type of audio stream*/
        format.mFormatID = kAudioFormatLinearPCM;
        /* flags specific to each format */
        format.mFormatFlags = kLinearPCMFormatFlagIsFloat
                | kLinearPCMFormatFlagIsPacked
                | kLinearPCMFormatFlagIsBigEndian;
-       /*
-        * We produce 2-channel audio. Now if we have a mega-super-hyper card for our
-        * audio, it is its problem to convert it to 8-, 16-, 32- or 1024-channel data.
-        */
-       format.mBytesPerFrame = (format.mFramesPerPacket = 1)
-               * (format.mBytesPerPacket = (format.mChannelsPerFrame = 2) * sizeof(float));
+       if (!conf->channels_given && wng->channels)
+               powd->channels = *wng->channels;
+       else
+               powd->channels = conf->channels_arg;
+       format.mChannelsPerFrame = powd->channels;
+       format.mFramesPerPacket = 1;
+       format.mBytesPerPacket = format.mChannelsPerFrame * sizeof(float);
+       format.mBytesPerFrame = format.mFramesPerPacket * format.mBytesPerPacket;
        /* one of the most constant constants of the whole computer history */
        format.mBitsPerChannel = sizeof(float) * 8;
        ret = -E_STREAM_FORMAT;