Changeset 455

Show
Ignore:
Timestamp:
04/09/07 04:25:12 (17 years ago)
Author:
ppalmers
Message:

- test-mixer volume control works (tested on phase88 only)
- volume control is exposed to the outside

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/bebob/bebob_functionblock.h

    r451 r455  
    138138 
    139139    virtual const char* getName(); 
     140     
     141    // FIXME: this is not pretty! 
     142    enum EControlSelectorEncoding { 
     143        eCSE_Feature_Unknown            = 0x00, 
     144        eCSE_Feature_Mute               = 0x01, 
     145        eCSE_Feature_Volume             = 0x02, 
     146        eCSE_Feature_LRBalance          = 0x03, 
     147        eCSE_Feature_FRBalance          = 0x04, 
     148        eCSE_Feature_Bass               = 0x05, 
     149        eCSE_Feature_Mid                = 0x06, 
     150        eCSE_Feature_Treble             = 0x07, 
     151        eCSE_Feature_GEQ                = 0x08, 
     152        eCSE_Feature_AGC                = 0x09, 
     153        eCSE_Feature_Delay              = 0x0a, 
     154        eCSE_Feature_BassBoost          = 0x0b, 
     155        eCSE_Feature_Loudness           = 0x0c, 
     156    }; 
    140157 
    141158protected: 
  • trunk/libffado/src/bebob/GenericMixer.cpp

    r451 r455  
    9494                        return OscResponse(OscResponse::eError); 
    9595                    } 
    96                     if(!(m->getArgument(3).isInt64() || m->getArgument(3).isFloat())) { 
     96                    if(!m->getArgument(3).isNumeric()) { 
    9797                        debugWarning("set selector: Wrong argument type\n"); 
    9898                        return OscResponse(OscResponse::eError); 
    9999                    } 
    100                          
    101                     int value=m->getArgument(3).getInt(); 
    102                      
    103                     if (m->getArgument(3).isFloat()) { 
    104                         value=(int)(m->getArgument(3).getFloat()); 
    105                     } 
     100                    int value=m->getArgument(3).toInt(); 
    106101                     
    107102                    return mixerSetSelectorValue(id, value); 
    108103                } 
    109104                 
     105                if (type == "volume") { 
     106                    if ( !(nbArgs==7)) { 
     107                        debugWarning("set volume: Wrong nb of arguments\n"); 
     108                        return OscResponse(OscResponse::eError); 
     109                    } 
     110                    if(!m->getArgument(3).isNumeric()) { 
     111                        debugWarning("set volume: Wrong argument (3) type\n"); 
     112                        return OscResponse(OscResponse::eError); 
     113                    } 
     114                    if(!m->getArgument(4).isNumeric()) { 
     115                        debugWarning("set volume: Wrong argument (4) type\n"); 
     116                        return OscResponse(OscResponse::eError); 
     117                    } 
     118                     
     119                    int channel=m->getArgument(3).toInt(); 
     120                    int volume=m->getArgument(4).toInt(); 
     121                     
     122                    return mixerSetFeatureVolumeValue(id, channel, volume); 
     123                } 
     124 
    110125                return OscResponse(OscResponse::eError); 
    111126            } 
     
    230245} 
    231246 
     247OscResponse  
     248GenericMixer::mixerSetFeatureVolumeValue(int fb_id, int channel,  
     249                                        int volume) { 
     250    OscMessage m; 
     251     
     252    debugOutput(DEBUG_LEVEL_NORMAL,"Set feature volume %d channel %d to %d...\n", 
     253        fb_id, channel, volume); 
     254 
     255    FunctionBlockCmd fbCmd( m_p1394Service, 
     256                            FunctionBlockCmd::eFBT_Feature, 
     257                            fb_id, 
     258                            FunctionBlockCmd::eCA_Current ); 
     259    fbCmd.setNodeId( m_device.getNodeId()  ); 
     260    fbCmd.setSubunitId( 0x00 ); 
     261    fbCmd.setCommandType( AVCCommand::eCT_Control ); 
     262    fbCmd.m_pFBFeature->m_audioChannelNumber=channel; 
     263    fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; 
     264    fbCmd.m_pFBFeature->m_pVolume->m_volume=volume; 
     265 
     266    if ( !fbCmd.fire() ) { 
     267        debugError( "cmd failed\n" ); 
     268    } 
     269 
     270    if (fbCmd.getResponse() != AVCCommand::eR_Accepted) { 
     271        return OscResponse(OscResponse::eError); 
     272    } 
     273 
     274    return OscResponse(m); 
     275} 
     276 
     277OscResponse  
     278GenericMixer::mixerGetFeatureVolumeValue(int fb_id, int channel) { 
     279    OscMessage m; 
     280     
     281    debugOutput(DEBUG_LEVEL_NORMAL,"Get feature volume %d channel %d...\n", 
     282        fb_id, channel); 
     283 
     284    FunctionBlockCmd fbCmd( m_p1394Service, 
     285                            FunctionBlockCmd::eFBT_Feature, 
     286                            fb_id, 
     287                            FunctionBlockCmd::eCA_Current ); 
     288    fbCmd.setNodeId( m_device.getNodeId()  ); 
     289    fbCmd.setSubunitId( 0x00 ); 
     290    fbCmd.setCommandType( AVCCommand::eCT_Status ); 
     291    fbCmd.m_pFBFeature->m_audioChannelNumber=channel; 
     292    fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; 
     293    fbCmd.m_pFBFeature->m_pVolume->m_volume=0; 
     294 
     295    if ( !fbCmd.fire() ) { 
     296        debugError( "cmd failed\n" ); 
     297    } 
     298 
     299    if (fbCmd.getResponse() != AVCCommand::eR_Accepted) { 
     300        return OscResponse(OscResponse::eError); 
     301    } 
     302     
     303    m.addArgument((int32_t)(fbCmd.m_pFBFeature->m_pVolume->m_volume)); 
     304 
     305    return OscResponse(m); 
     306} 
    232307 
    233308} // end of namespace BeBoB 
  • trunk/libffado/src/bebob/GenericMixer.h

    r451 r455  
    5151    OSC::OscResponse mixerGetSelectorValue(int id); 
    5252    OSC::OscResponse mixerSetSelectorValue(int id, int value); 
     53     
     54    OSC::OscResponse mixerSetFeatureVolumeValue(int id, int channel, int volume); 
     55    OSC::OscResponse mixerGetFeatureVolumeValue(int fb_id, int channel); 
     56     
    5357protected: 
    5458    Ieee1394Service      &m_p1394Service; 
  • trunk/libffado/src/libavc/avc_function_block.cpp

    r445 r455  
    11/* 
    22 * Copyright (C) 2005-2007 by Daniel Wagner 
     3 * Copyright (C) 2005-2007 by Pieter Palmers 
    34 * 
    45 * This file is part of FFADO 
     
    3031FunctionBlockFeatureVolume::FunctionBlockFeatureVolume() 
    3132    : IBusData() 
    32     , m_controlSelector( FunctionBlockFeature::eCSE_Feature_Volume ) 
    3333    , m_controlDataLength( 2 ) 
    3434    , m_volume( 0 ) 
     
    3737 
    3838FunctionBlockFeatureVolume::FunctionBlockFeatureVolume( const FunctionBlockFeatureVolume& rhs ) 
    39     : m_controlSelector( rhs.m_controlSelector ) 
    40     , m_controlDataLength( rhs.m_controlDataLength ) 
     39    : m_controlDataLength( rhs.m_controlDataLength ) 
    4140    , m_volume( rhs.m_volume ) 
    4241{ 
     
    5251    bool bStatus; 
    5352    byte_t val; 
    54     bStatus = se.write( m_controlSelector,    "FunctionBlockFeatureVolume controlSelector" ); 
    55     bStatus &= se.write( m_controlDataLength,  "FunctionBlockFeatureVolume controlDataLength" ); 
     53    bStatus = se.write( m_controlDataLength,  "FunctionBlockFeatureVolume controlDataLength" ); 
    5654    val = (byte_t)(m_volume >> 8); 
    5755    bStatus &= se.write( val,                  "FunctionBlockFeatureVolume volume high" ); 
     
    6765    bool bStatus; 
    6866    byte_t val; 
    69     bStatus = de.read( &m_controlSelector ); 
    70     bStatus &= de.read( &m_controlDataLength ); 
     67    bStatus = de.read( &m_controlDataLength ); 
    7168    bStatus &= de.read( &val ); 
    7269    m_volume = val << 8; 
     
    327324    , m_selectorLength( 0x02 ) 
    328325    , m_audioChannelNumber( 0x00 ) 
    329     , m_pVolume( 0 ) 
     326    , m_controlSelector( eCSE_Feature_Unknown ) 
     327    , m_pVolume( new FunctionBlockFeatureVolume ) 
    330328{ 
    331329} 
     
    335333    , m_selectorLength( rhs.m_selectorLength ) 
    336334    , m_audioChannelNumber( rhs.m_audioChannelNumber ) 
     335    , m_controlSelector( rhs.m_controlSelector ) 
    337336{ 
    338337    if ( rhs.m_pVolume ) { 
     
    344343{ 
    345344    delete m_pVolume; 
    346     m_pVolume = 0
     345    m_pVolume = NULL
    347346} 
    348347 
     
    353352    bStatus  = se.write( m_selectorLength,     "FunctionBlockFeature selectorLength" ); 
    354353    bStatus &= se.write( m_audioChannelNumber, "FunctionBlockFeature audioChannelNumber" ); 
    355  
    356     if ( m_pVolume ) { 
     354    bStatus &= se.write( m_controlSelector,    "FunctionBlockFeature controlSelector" ); 
     355 
     356    if ( m_controlSelector == eCSE_Feature_Volume ) { 
    357357        bStatus &= m_pVolume->serialize( se ); 
    358358    } else { 
     
    369369    bStatus  = de.read( &m_selectorLength ); 
    370370    bStatus &= de.read( &m_audioChannelNumber ); 
    371  
    372     byte_t controlSelector; 
    373     bStatus &= de.peek( &controlSelector ); 
    374     switch( controlSelector ) { 
     371    bStatus &= de.read( &m_controlSelector ); 
     372 
     373    switch( m_controlSelector ) { 
    375374    case eCSE_Feature_Volume: 
    376         if ( !m_pVolume ) { 
    377             m_pVolume = new FunctionBlockFeatureVolume; 
    378         } 
    379375        bStatus &= m_pVolume->deserialize( de ); 
    380376        break; 
  • trunk/libffado/src/libavc/avc_function_block.h

    r445 r455  
    4343    virtual FunctionBlockFeatureVolume* clone() const; 
    4444 
    45     control_selector_t     m_controlSelector; 
    4645    control_data_length_t  m_controlDataLength; 
    4746    u_int16_t              m_volume; 
     
    147146    virtual FunctionBlockFeature* clone() const; 
    148147 
    149     selector_length_t      m_selectorLength; 
    150     audio_channel_number_t m_audioChannelNumber; 
     148    selector_length_t           m_selectorLength; 
     149    audio_channel_number_t      m_audioChannelNumber; 
     150    control_selector_t          m_controlSelector; 
    151151 
    152152    FunctionBlockFeatureVolume*     m_pVolume; 
  • trunk/libffado/tests/test-mixer.cpp

    r447 r455  
    8989 
    9090bool 
    91 doApp2( Ieee1394Service& ieee1394service, int node_id, int fb_id ) 
     91selectorGet( Ieee1394Service& ieee1394service, int node_id, int fb_id ) 
    9292{ 
    9393    FunctionBlockCmd fbCmd( ieee1394service, 
     
    120120 
    121121bool 
    122 doApp3( Ieee1394Service& ieee1394service, int node_id, int fb_id , int val ) 
     122selectorSet( Ieee1394Service& ieee1394service, int node_id, int fb_id , int val ) 
    123123{ 
    124124    FunctionBlockCmd fbCmd( ieee1394service, 
     
    132132 
    133133    debugOutput(DEBUG_LEVEL_NORMAL, "Setting selector state to %d...\n", val); 
     134 
     135    fbCmd.setVerbose( bVerbose ); 
     136    if (bVerbose) { 
     137        ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE ); 
     138    } 
     139     
     140    if ( !fbCmd.fire() ) { 
     141        debugError( "cmd failed\n" ); 
     142    } 
     143 
     144    if ( bVerbose ) { 
     145        CoutSerializer se; 
     146        fbCmd.serialize( se ); 
     147    } 
     148 
     149    return true; 
     150} 
     151 
     152bool 
     153volumeGet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel ) 
     154{ 
     155    FunctionBlockCmd fbCmd( ieee1394service, 
     156                            FunctionBlockCmd::eFBT_Feature, 
     157                            fb_id, 
     158                            FunctionBlockCmd::eCA_Current ); 
     159    fbCmd.setNodeId( node_id ); 
     160    fbCmd.setSubunitId( 0x00 ); 
     161    fbCmd.setCommandType( AVCCommand::eCT_Status ); 
     162    fbCmd.m_pFBFeature->m_audioChannelNumber=channel; 
     163    fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; 
     164    fbCmd.m_pFBFeature->m_pVolume->m_volume=0; 
     165 
     166    debugOutput(DEBUG_LEVEL_NORMAL, "Requesting volume feature block state...\n"); 
     167 
     168    fbCmd.setVerbose( bVerbose ); 
     169    if (bVerbose) { 
     170        ieee1394service.setVerboseLevel( DEBUG_LEVEL_VERY_VERBOSE ); 
     171    } 
     172     
     173    if ( !fbCmd.fire() ) { 
     174        debugError( "cmd failed\n" ); 
     175    } 
     176 
     177    if ( bVerbose ) { 
     178        CoutSerializer se; 
     179        fbCmd.serialize( se ); 
     180    } 
     181 
     182    return true; 
     183} 
     184 
     185bool 
     186volumeSet( Ieee1394Service& ieee1394service, int node_id, int fb_id, int channel, int value ) 
     187{ 
     188    FunctionBlockCmd fbCmd( ieee1394service, 
     189                            FunctionBlockCmd::eFBT_Feature, 
     190                            fb_id, 
     191                            FunctionBlockCmd::eCA_Current ); 
     192    fbCmd.setNodeId( node_id ); 
     193    fbCmd.setSubunitId( 0x00 ); 
     194    fbCmd.setCommandType( AVCCommand::eCT_Control ); 
     195    fbCmd.m_pFBFeature->m_audioChannelNumber=channel; 
     196    fbCmd.m_pFBFeature->m_controlSelector=FunctionBlockFeature::eCSE_Feature_Volume; 
     197    fbCmd.m_pFBFeature->m_pVolume->m_volume=value; 
     198 
     199    debugOutput(DEBUG_LEVEL_NORMAL, "Setting volume feature block channel %d state to %d...\n", channel, value); 
    134200 
    135201    fbCmd.setVerbose( bVerbose ); 
     
    157223{ 
    158224 
    159     if (argc < 3) { 
    160         debugError("usage: PORT NODE_ID FB_ID\n"); 
     225    if (argc < 4) { 
     226        debugError("usage: PORT NODE_ID CMD FB_ID [VAL1] [VAL2]\n"); 
    161227        exit(0); 
    162228    } 
     
    166232    int port = strtol( argv[1], &tail, 0 ); 
    167233    int node_id = strtol( argv[2], &tail, 0 ); 
    168     int fb_id   = strtol( argv[3], &tail, 0 ); 
    169  
     234    int cmd = strtol( argv[3], &tail, 0 ); 
     235    int fb_id   = strtol( argv[4], &tail, 0 ); 
     236     
     237    int value1=-1; 
     238    int value2=-1; 
     239     
     240    if (argc>=6) 
     241        value1 = strtol(argv[5], &tail, 0 ); 
     242         
     243    if (argc>=7) 
     244        value2 = strtol(argv[6], &tail, 0 ); 
     245     
    170246    if (errno) { 
    171247        debugError("argument parsing failed: %s", strerror(errno)); 
     
    178254    } 
    179255 
    180     doApp( ieee1394service, node_id, fb_id ); 
    181     doApp2( ieee1394service, node_id, fb_id ); 
    182      doApp3( ieee1394service, node_id, fb_id , 0 ); 
    183      sleep(1); 
    184      doApp3( ieee1394service, node_id, fb_id , 1 ); 
    185      sleep(1); 
    186      doApp3( ieee1394service, node_id, fb_id , 0 ); 
     256    switch(cmd) { 
     257    case 0: 
     258        doApp( ieee1394service, node_id, fb_id ); 
     259        break; 
     260    case 1: 
     261        selectorGet( ieee1394service, node_id, fb_id ); 
     262        break; 
     263    case 2: 
     264        selectorSet( ieee1394service, node_id, fb_id , value1 ); 
     265        break; 
     266    case 3: 
     267        volumeGet( ieee1394service, node_id, fb_id, value1); 
     268        break; 
     269    case 4: 
     270        volumeSet( ieee1394service, node_id, fb_id, value1, value2); 
     271        break; 
     272    } 
    187273 
    188274    return 0;