Changeset 947:d2ba2ac865ab in mediastreamer2


Ignore:
Timestamp:
Apr 15, 2010 1:27:01 PM (3 years ago)
Author:
Aymeric Moizard <jack@…>
Branch:
default
Message:

add support for volume control in AudioUnit?

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/aqsnd.c

    r946 r947  
    7272#define kNumberAudioInDataBuffers       4 
    7373 
    74 float gain_volume_in=1.0; 
    75 float gain_volume_out=1.0; 
    76 bool gain_changed_in = true; 
    77 bool gain_changed_out = true; 
     74static float gain_volume_in=1.0; 
     75static float gain_volume_out=1.0; 
     76static bool gain_changed_in = true; 
     77static bool gain_changed_out = true; 
    7878 
    7979#ifdef TARGET_OS_IPHONE 
     
    151151                case MS_SND_CARD_PLAYBACK: 
    152152                case MS_SND_CARD_MASTER: 
    153                         { 
    154                         } 
    155153                  return (int)(gain_volume_out*100.0f); 
    156154                case MS_SND_CARD_CAPTURE: 
  • src/macsnd.c

    r945 r947  
    5656MSFilter *ms_ca_write_new(MSSndCard *card); 
    5757 
     58static float gain_volume_in=1.0; 
     59static float gain_volume_out=1.0; 
     60static bool gain_changed_in = true; 
     61static bool gain_changed_out = true; 
     62 
    5863typedef struct CAData{ 
    5964        int dev; 
     
    8893static void cacard_set_level(MSSndCard *card, MSSndCardMixerElem e, int percent) 
    8994{ 
     95        switch(e){ 
     96                case MS_SND_CARD_PLAYBACK: 
     97                case MS_SND_CARD_MASTER: 
     98                        gain_volume_out =((float)percent)/100.0f; 
     99                        gain_changed_out = true; 
     100                        return; 
     101                case MS_SND_CARD_CAPTURE: 
     102                        gain_volume_in =((float)percent)/100.0f; 
     103                        gain_changed_in = true; 
     104                        return; 
     105                default: 
     106                        ms_warning("cacard_set_level: unsupported command."); 
     107        } 
    90108} 
    91109 
    92110static int cacard_get_level(MSSndCard *card, MSSndCardMixerElem e) 
    93111{ 
     112        switch(e){ 
     113                case MS_SND_CARD_PLAYBACK: 
     114                case MS_SND_CARD_MASTER: 
     115                        return (int)(gain_volume_out*100.0f); 
     116                case MS_SND_CARD_CAPTURE: 
     117                        return (int)(gain_volume_in*100.0f); 
     118                default: 
     119                        ms_warning("cacard_get_level: unsupported command."); 
     120        } 
    94121        return -1; 
    95122} 
     
    537564        memcpy(rm->b_wptr, d->fMSBuffer->mBuffers[0].mData, ActualOutputFrames*2); 
    538565        rm->b_wptr+=ActualOutputFrames*2; 
     566         
     567        if (gain_volume_in != 1.0f) 
     568        { 
     569                int16_t *ptr=(int16_t *)rm->b_rptr; 
     570                for (;ptr<(int16_t *)rm->b_wptr;ptr++) 
     571                { 
     572                        *ptr=(int16_t)(((float)(*ptr))*gain_volume_in); 
     573                } 
     574        } 
     575         
    539576        ms_mutex_lock(&d->mutex); 
    540577        putq(&d->rq,rm); 
     
    555592    void *inInputDataProcUserData=NULL; 
    556593        CAData *d=(CAData*)inRefCon; 
     594        if (gain_changed_out == true) 
     595        { 
     596                err = AudioUnitSetParameter(d->caOutAudioUnit, kAudioUnitParameterUnit_LinearGain, 
     597                                                                           kAudioUnitScope_Global, 0, (Float32)gain_volume_out, 0); 
     598                if(err != noErr) 
     599                { 
     600                        ms_error("failed to set output volume %i", err); 
     601                } 
     602            gain_changed_out = false; 
     603                err= noErr; 
     604        } 
     605         
     606         
    557607        if(d->write_started != FALSE) { 
    558608                AudioStreamPacketDescription* outPacketDescription = NULL; 
     
    664714        if(result != noErr) 
    665715        { 
    666                 fprintf(stderr, "failed to get audio sample size\n"); 
     716                ms_error("failed to get audio sample size"); 
    667717                return -1; 
    668718        } 
     
    671721        if(result != noErr) 
    672722        { 
     723                ms_error("failed to AudioUnitInitialize input %i", result); 
    673724                return -1; 
    674725        } 
     
    679730        if(d->fAudioBuffer == NULL) 
    680731        { 
    681                 fprintf(stderr, "failed to allocate buffers\n"); 
     732                ms_error("failed to allocate buffers fAudioBuffer"); 
    682733                return -1; 
    683734        } 
     
    687738        if(d->fMSBuffer == NULL) 
    688739        { 
    689                 fprintf(stderr, "failed to allocate buffers\n"); 
     740                ms_error("failed to allocate buffers fMSBuffer"); 
    690741                return -1; 
    691742        } 
     743         
    692744        return 0; 
    693745} 
     
    776828        if(result != noErr) 
    777829        { 
     830                ms_error("failed to AudioUnitInitialize output %i", result); 
    778831                return -1; 
    779832        } 
Note: See TracChangeset for help on using the changeset viewer.