起始

 

 

1  Overview

This section describes the system design of MAS and MTK MAS Block. 

In Figure 1-1, MAS  Structure is composed of 5 parts:

· ALSA playback application and MAS is different with process or thread.

· If ALSA playback want to use MAS, pcm device node “main” ”sub0” “sub1” will  be used.

· MAS is created by a control application. It is the same with process as control application

· Control application can set different property of MAS ,like volume, output sample rate rule, output device and so on by using MAS library interface.

 

· For one system, there is only one MAS instance.

 

2  MSA Library API

This chapter offers some APIS of MAS  in common use, which helps user to get started quickly. Mediatek will provide header files and libmas2.so , then Customers can use them.

2.1  MAS Header File Introduction

  • Header Files: The head files set which supported by mas. Table 2-1 is the head files list:

     

2.2  MAS Library

Mediatek will provide header files and libmas2.so , then Customers can use them as Figure2-1.

  •  Mas lib is a Mediatek audio service and used to start mas service .
  • Its purpose is to play some applications and write data to alsa node.
  • The data from playback can send to mas service ,then you can do PowerAQ and mix process.

                                  Figure 2-1.  Libmas2.so Path.

 

2.3  MAS API List

This section introduces the functions for Mas connection. Note that all functions from MTK Mas, the detail information shows in Table 2-3.

2.4  API Detail Information

This chapter introduces the API Interface define and function in MAS service. 

2.4.1  mas_create Function

  • API Define
    • int mas_create(void **handle);

          It is used to create Mediatek audio service.  Only one Mediatek audio service can be created in one system.

  •  Parameters
    • handle :  It is Mediatek audio service handler.

          If return value is OK, this value is valuable. It must be used when you call other APIs of the mas.

  • Return Value
    • 0                  OK
    • Others       Fail

       NOTE:  About detail fail type, please reference to  the LINUX standard error type define.

 

 

 

2.4.2  mas_destroy

  • API Define
    • int mas_destroy(void *handle);

-          It is used to destroy Mediatek audio service.

  • Parameters
    • handle :  the Mediatek audio service handler which is got from mas_create
  • Return Value
    • 0                  OK
    • Others       Fail

Note: About detail fail type, please reference the LINUX error type define.

 

2.4.3  mas_start

  • API Define
  • int mas_start(void *handle);

 It is used to start Mediatek audio service. Only the Funtion is called, the Mas playback can be started.

And user can do some initial setting between mas_create and mas_start. Like device setting, volume setting init.

  • Parameters
  • handle :  Mediatek audio service handler which is got from mas_create
  • Return Value
  • 0                 OK
  • Others       Fail

               Note: About detail fail type, please reference the LINUX error type define.

 

2.4.4  mas_stop

  • API Define
  • int mas_stop(void *handle);

 It is used to stop Mediatek audio service.  This function must be called before mas_destroy.

 Make sure that there is no any mas playback when this function is executed.

  • Parameters
  • handle :  Mediatek audio service handler which is got from mas_create
  • Return Value
  • 0                  OK
  • Others       Fail

           Note : About detail fail type, please reference the LINUX error type define.

 

2.4.5  mas_set_master_vol

  • API Define
  • int mas_set_master_vol(void *handle,  int level);

It is used to set master volume, and the master volume can affect all the audio playback stream,

 The final output volume is affected by both of master volume and stream volume.

  • Parameters
  • handle :  Mediatek audio service handler which is got from mas_create.
  • level    :   Value range 0 ~ 100,  0 means mute, 100 means 0db.
  • Return Value
  •  0                 OK
  • Others       Fail

Note :About detail fail type, please reference the LINUX error type define.

 

2.4.6  mas_set_stream_vol

  • API Define
  • int mas_set_stream_vol(void *handle, mas_audio_stream_type_t streamType,  int level);

It is used to set stream volume. The stream volume can only affect the specific audio playback stream.

The final output volume is affected by both of master volume and stream volume.

  • Parameters
    handle         :  Mediatek audio service handler which is got from mas_create.
    streamType :  Audio stream type, the type that can support as follows in Figure 2-2.

                      Figure 2‑2. MAS API StreamType.

    Note: 1.Only media stream support audio PP. 

        2. MAS_AUDIO_STREAM_MEDIA        => for “main” device playback

        3. MAS_AUDIO_STREAM_SYSTEM1  => for “sub0” device playback

        4. MAS_AUDIO_STREAM_SYSTEM2  => for “sub1” device playback

    Level:   value range 0 ~ 100,   0 means mute,  100 means 0db.
     

Return Value

  •  0                OK
  • Others       Fail

Note: About detail fail type, please reference the LINUX error type define.

 

2.4.7  mas_set_device_connection

 

  • API Define
  • int mas_set_device_connection(void *handle, mas_aud_device_t dev,  mas_device_config_t *devConfig);

-          It is used to add a new device to mas.  If this action cause output device change, the current playback will be reset(stop=>play).

  • Parameters
    • handle :  Mediatek audio service handler which is got from mas_create.
    • dev        :  Now only support following 2 kinds device as Figure 2-3.

Figure 2‑3. MAS Connection API Type .

     

Note: 

  •  Speaker is attached device in mas. It only supports description modification, does not support connection and disconnection operation.
  •  BT output hal is not development now. When you set BT device, it will use dummy output now.
     
  • devConfig: It means device configuration description. In the connection setting,    hw_spk_chmap can not be NULL.
  1.  hw_spk_chmap is NULL, user_spk_chmap is NULL.  => not support
  2.  hw_spk_chmap is NULL, user_spk_chmap is not NULL. => not support
  3.  hw_spk_chmap is not NULL, user_spk_chmap is NULL.
  4.   hw_spk_chmap will be checked, If it is valid, it will be set to device.
  5.   user_spk_chmap of the device will generated from  hw_spk_chmap.
  6.   hw_spk_chmap is not NULL, user_spk_chmap is not NULL.
  7.   hw_spk_chmap and user_spk_chmap will be checked, If it is valid, they will be set to device.

We can get more information as Figure 2-4, Please see the struct and define.

Figure 2‑4. MAS Ch-map Type .

Channels:the audio output hardware channel number.  Now mas can only support max 8ch for data process.

Chmap:the channel map of audio output hardware. The channel position order in the channel map is also cared in hw_spk_chmap.

MAS_CHMAP_DUMMY:just output 0 data for target position. In some hardware or board, output data channels must be more than real speaker. So MAS_CHMAP_DUMMY is need for output.

Eg: I2S Speaker driver cannot output 1ch, so if real speaker only 1 channel. hw_spk_chmap must be set to MAS_CHMAP_DUMMY, MAS_CHMAP_FC.

hw_spk_chmap:the max capability of hardware speaker support in board. Some channels of it will not output sound, so MAS_CHMAP_DUMMY is used. It does not support 2 same channel position.  It can include MAS_CHMAP_DUMMY channel. Its channel number is multiple times of 2.         

user_spk_chmap:the user specific hardware speaker which will really output sound.  It does not support 2 same channel position. It cannot include MAS_CHMAP_DUMMY channel.  Its channel positions must be included in hw_spk_chmap.

Eg: I2S speaker driver only support 2, 4, 6, 8ch output.  For 2.1ch speaker design, the connection order of speaker and I2S interface is L Channel speaker, R Channel Speaker, None, LFE channel speaker.

In this case hw_spk_chmap must be set to 4ch, channel map and order is

  1. MAS_CHMAP_FL.
  2. MAS_CHMAP_FR.
  3. MAS_CHMAP_DUMMY.
  4. MAS_CHMAP_LFE.

Application can control speaker which can output sound by using user_spk_chmap. If 2.1ch speaker all output sound, user_speaker_chmap can be set to MAS_CHMAP_FL, MAS_CHMAP_FR,MAS_CHMAP_LFE.If 2ch speaker output sound, user_speaker_chamap can be set to MAS_CHMAP_FL, MAS_CHMAP_FR.

 

  • Return Value

0                  OK

Others       Fail
Note: About detail fail type, please reference the LINUX error type define.

 

2.4.8  mas_set_device_disconnection

  • API Define
  • int mas_set_device_disconnection(void *handle, mas_aud_device_t  dev);

-          It is used to remove a device from mas.  If the action cause output device change, the current playback will be reset(stop=>play).

  • Parameters
  • handle : Mediatek audio service handler which is got from mas_create
  • dev      :  Now only support following 2 kinds device as Figure 2-5.
     

 

 

 

       

 Figure 2‑5. MAS Parameters Type .

 

Note:  Speaker is attached device in mas. It only supports description modification, does not support connection and disconnection operation.

  • Return Value
  • 0                  OK
  • Others       Fail

NoteAbout detail fail type, please reference the LINUX error type define.

 

2.4.9  mas_set_device_desc

  • API Define
  • int mas_set_device_desc(void *handle, mas_aud_device_t dev,  mas_device_config_t *devConfig);

-          It is used to modify the description of device.  If the action cause output format change, the current playback will be reset(stop=>play).

  • Parameters
  • handle  :  Mediatek audio service handler which is got from mas_create.
  • dev         :  Now only support following 2 kinds device as Figure 2-6.
     

 

 

 

Figure 2‑6. MAS Parameters Type .

 

Note:  Only one device is connected, its description can be modified. BT device is not support now.

 

  • devConfig :   device configuration description.

hw_spk_chmap and user_spk_chmap is NULL.     => Not support.

hw_spk_chmap and NULL,user_spk_chmap are not NULL=> only config user_spk_chmap.

user_spk_chmap will checked with last hw_spk_chmap setting. If it is  valid,it will be set to device.

 hw_spk_chmap is not NULL  user_spk_chmap is NULL=> only config hw_spk_chmap.

hw_spk_chmap will be checked .if it is valid, it will be set to device.

user_spk_chmap of the device will generated from  hw_spk_chmap.

Both hw_spk_chmap and user_spk_chmap  are not NULL

hw_spk_chmap and user_spk_chmap will be checked . If it is valid,    they will be set to device.

  Note: About detail structure of devConfig, please refer 2.3.7

  •  Return Value
  • 0                  OK
  • Others       Fail

                                About detail fail type, please reference the LINUX error type define.

 

2.4.10  mas_ppc_set_parameter

  • API Define
  • int mas_ppc_set_parameter(void *handle, unsigned int element_id, unsigned int para_id, unsigned int para_num, int *value);

-          It is used to set parameter to a specific element.

  • Parameters
  • handle        :  Mediatek audio service handler which is got from mas_create.
  • element_id :  An unique id which represents a specific element in a specific post processing chain. It is defined in id.h which is generated from PowerAQ tool.
  • para_id       :   An id that indicates the value of which parameter is going to be set. It is defined in id.h which is generated from PowerAQ tool.
  • para_num  : The number of parameter value (usually 16, the total channel number supports by PowerAQ).
  • value            :  an array of parameter values that is going to be set.
  • Return Value
  • 0               OK
  • Others    Fail

 

2.4.11  mas_ppc_get_parameter

  • API Define
  • int mas_ppc_get_parameter(void *handle, unsigned int element_id, unsigned int para_id, unsigned int para_num, int *value);

-          This function can get the current value of a parameter in a specific post processing element.

  • Parameters
  • handle       :  Mediatek audio service handler which is got from mas_create
  • element_id:  An unique id which represents a specific element in a specific post processing chain. It is defined in id.h which is generated from PowerAQ tool.
  • para_id     :   An id that indicates the value of which parameter is going to be read. It is defined in id.h which is generated from PowerAQ tool.
  • para_num :  The number of parameter value (usually 16, the total channel number supports by PowerAQ)
  • value        :  An array that is going to be filled by the parameter values.
  • Return Value
  • 0                OK
  • Others      Fail

 

2.4.12 mas_ppc_set_element_bypass

  • API Define
  • int mas_ppc_set_element_bypass(void *handle, unsigned int element_id, int enable);

-          It is used to enable or disable bypass one of the element in a specific chain.

  • Parameters
  • handle        :  Mediatek audio service handler which is got from mas_create.
  • element_id :  An unique id which represents a specific element in a specific post processing chain. It is defined in id.h which is generated from PowerAQ tool.
  • enable        :   Enable (1) or disable (0) element bypass.
  • Return Value
  • 0                OK
  • Others       Fail

 

2.4.13  mas_ppc_get_element_bypass

  • API Define
  • int mas_ppc_get_element_bypass(void *handle, unsigned int element_id, int* enabled);

-          This Function can get the bypass status of the element in a specific chain.

  • Parameters
  • handle        :    Mediatek audio service handler which is got from mas_create.
  • element_id :  An unique id which represents a specific element in a specific post processing chain. It is defined in id.h which is generated from PowerAQ tool.
  • enabled      :   Filled by PPC to indicates the element bypass status. enable (1) or disable (0).
  • Return Value
  •           OK
  • Others   Fail

2.4.1 4 mas_ppc_set_cfgfile_path

  • API Define
  • int mas_ppc_set_cfgfile_path(void *handle,  const char *path);

  It is used to define which path PPC used to find and read config files.

  If this API is called during playback to change the config files used by PowerAQ Tool, AudioPPCControl::open should be called again.

  • Parameters
  • handle        :  Mediatek audio service handler which is got from mas_create.
  • path            :  The path PowerAQ will go to read config files.
  • Return Value
  • 0            OK
  • Others   Fail

 

2.4.16  mas_ppc_get_cfgfile_path

  • API Define
  • int mas_ppc_get_system_info(void *handle, void *ppc_sys_info);

           It is used to obtain the current system info from PPC.

  • Parameters
  • handle            :  Mediatek audio service handler which is got from mas_create.
  • ppc_sys_info :  A pointer to the struct which contains the system information. PPC would fill each member in it.
  • Return Value
  • 0            OK
  • Others   Fail

 

2.4.17   mas_ppc_set_mode

  • API Define
  • int mas_ppc_set_mode(void *handle, int ppc_mode);

It is used to tell PPC which mode is going to be used for playback and PPC would use it to choose the appropriate chain.

If this API is not called before playback starts, a default mode (movie) would be used by PPC and a wrong chain might be chosen and applied.

If this API is called during playback to change, AudioPPCControl::open() should be called again.

  • Parameters
  • handle        :  Mediatek audio service handler which is got from mas_create.
  • ppc_mode :  The effect mode which is going to be used for playback. 1 for MOVIE mode and 2 for MUSIC mode.
  • Return Value
  • 0           OK
  • Others   Fail

2.4.18  mas_ppc_get_mode

  • API Define
  • int mas_ppc_get_mode(void *handle);

           It is used to obtain the current PPC mode used for playback.

  • Parameters
  • handle :  Mediatek audio service handler which is got from mas_create.
  • Return Value
  • 1           MOVIE mode
  •          MUSIC mode

 

2.4.19   mas_ppc_dump_element_data

  • API Define
  • int mas_ppc_dump_element_data(void *handle, unsigned int element_id,  int enabled, char *dump_folder);

-          It is used to dump input and output data of a specific element in a specific chain.

-          This API should be called after AudioPPCControl::open() is called.

  • Parameters
  • handle           :  Mediatek audio service handler which is got from mas_create.
  • element_id  :  An unique id which represents a specific element in a specific post processing chain.  It is defined in id.h which is generated from PPC tool.
  • enabled          :   enable (1) or disable (0) the data dump of a specific element.
  • dump_folder : The folder is used to store dump data.
  • Return Value
  • 0            OK
  • Others   Fail

 

2.4.20  mas_ppc_dump_config_status

  • API Define
  • int mas_ppc_dump_config_status(void *handle,  char *config_path);

-          save the all the information of PPC into config files.

  • Parameters
  • handle        :  Mediatek audio service handler which is got from mas_create.
  • config_path :  The folder is used to store saved config files.

 

  • Return Value
  • 0            OK
  • Others   Fail

 

2.4.21  mas_ppc_enable

  • API Define
  • int mas_ppc_enable(void *handle,  mas_ppc_position_t pos, int enable);

-          Enable / Disable ppc in some position.

  • Parameters
  • handle      :  Mediatek audio service handler which is got from mas_create.
  • pos            :  The ppc enable/disable will be executed in the position which is showed in Figure2-7.
     

.

 

Note:

  1. MAS_PPC_STREAM_MEDIA_PROC       => PPC  after “main” and before mix out position
  2. MAS_PPC_MIXER_OUT                                => PPC after the mix out position

         

Figure 2‑8. MAS  FLOW .

  1.  Since now only support 1 PPC instance, so there is only 1 PPC position can be enabled.  If you want change PPC enable from one position to another position, you must be disabled the position that be already enabled firstly.

NOTE: enable value:  1  enable  , 0  disable.

  • Return Value
  • 0               OK
  • Others      Fail

2.4.22  mas_ppc_src_enable

  • API Define
  • int mas_ppc_enable(void *handle,  mas_audio_stream_t stream, int enable);

-          Enable / Disable src before ppc in some stream playback.

After enable, only meet following condition, the ppc src can be run.

-           Ppc is enable and will be run.

-           Playback source sample rate can not be 32Khz, 48Khz, 44.1Khz.

  • Parameters
  • handle :  Mediatek audio service handler which is got from mas_create
  • stream :  the ppc src enable/disable will be executed in which stream.
     

 

 

 

 

Figure 2‑9. MAS  PPC SRC ENABLE VALUE .

 

 

Note:

 a. Now only MAS_AUDIO_STREAM_MEDIA can support ppc.

                 b. MAS_AUDIO_STREAM_MEDIA       => for “main” device playback

                 c. MAS_AUDIO_STREAM_SYSTEM1  => for “sub0” device playback

                 d. MAS_AUDIO_STREAM_SYSTEM2  => for “sub1” device playback

         enable value:  1 enable   0 disable.

  • Return Value
  • 0               OK
  • Others      Fail
     

 

2.4.23  mas_set_out_samplerate_rule

  • API Define
  • int mas_set_out_samplerate_rule(void *handle,  mas_samplerate_rule_t rule, int rate);

-          Set mas playback output sample rate rule. If the rule is changed, the current playback will be reset(stop=>play).

  • Parameters
  • handle :  Mediatek audio service handler which is got from mas_create.
  • rule      :  the output sample rate config rule as Figure 2-10.

  Figure 2‑10. MAS  Set Sample Rate .

 

Note:

a. MAS_OUT_SR_FIX means that the output sample rate is fix to value of rate.When this rule is set, the rate must be a value in “8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000, 176400, 192000 “

b. MAS_OUT_SR_DYNAMIC_MAIN means that the output sample rate is dynamic decided. When this rule is set, the rate is set to 0. output sample rate is decided as following rule.

-          If there is only 1 playback, the source sample rate of playback in main/sub0/sub1 is the output sample rate.

-          If there is multi-playback, and there is no main playback, the source sample rate of first playback is the output sample rate.

-          If there is multi-playback, and there is a main playback, the source sample rate of main playback is the output sample rate.

  • Return Value
  •                OK
  • Others       Fail

 

2.4.24  mas_set_out_buffer_rule

  • API Define
  • int mas_set_out_buffer_rule(void *handle,  mas_out_buffer_rule_t rule);

-          Set mas playback output buffer rule. If buffer rule is changed, the current output will not be reset to apply new setting. The next playback will apply the new setting.

  • Parameters
  • handle        :  Mediatek audio service handler which is got from mas_create.
  • rule             :  Output buffer rule.

Figure 2‑10. MAS  Out buffer rule. 

 

Note:

a.Period_time is the value that set to kernel, so that the time hardware will trigger 1 interrupt.  and also Mas internal process unit will be same with the value.

-           If output buffer rule is not set, the default period time is 20ms.

-           If output buffer rule is set, the period_time must >=5ms

b. Application which use “main” “sub0” “sub1” as ALSA pcm device,  their playback buffer time must >= period_time,  otherwise the Mas will not mix the input data. Here we suggest the playback buffer time at least 2 times of period_time.

c.   Period_num is the value set to kernel that how long kernel buffer is allocated.

-          If output rule is not set, the default period_num is 2

-          If playback is complex, period_time * period_num  is suggested >= 80ms

d. start_threadhold is the value when the hardware is be started.

  • Return Value
  • 0               OK
  • Others      Fail
     

2.4.25  mas_set_device_connection_ext

  • API Define
  • int mas_set_device_connection_ext(void *handle, mas_aud_device_t  dev,  mas_device_config_ext_t *devConfig);

-          It is used to add a new device to mas.  If the action cause output device change, the current playback will be reset(stop=>play).

  • Parameters
  • handle         :  Mediatek audio service handler which is got from mas_create.
  • dev              :  for now only support following 2 kinds device as Figure 2-11.

 

Figure 2‑11. MAS Set Device Connection value. 

Note: 

Speaker is attached device in mas. It only supports description modification,  but it does not support connection and disconnection operation.

BT output hal is not development now. When you set BT device, it will use dummy output now.

devConfig :   device configuration description. In connection setting, hw_spk_chmap can not be NULL.

-           hw_spk_chmap is NULL, user_spk_chmap is NULL.  => not support

-           hw_spk_chmap is NULL, user_spk_chmap is not NULL. => not support

-           hw_spk_chmap is not NULL, user_spk_chmap is NULL.hw_spk_chmap will be checked,If it is valid, it will be set to device.user_spk_chmap of the device will generated from  hw_spk_chmap.

-           hw_spk_chmap is not NULL, user_spk_chmap is not NULL.

-          hw_spk_chmap and user_spk_chmap will be checked,If it is valid, they will be set to device.

 

 

Figure 2‑12. MAS Set Device Connection value. 

Note:

-          hw_spk_chmap,user_spk_chmap usage is same with mas_set_device_connection in 2.3.7

-          bits means which bitdepth the current device use,  now only support 16bit/32bit.

-          If bits is set 0, or the mas_set_device_connection is called, the output bitdepth is 32.

-          addr means which output address current device is used. For speaker if the value is NULL, or the mas_set_device_connection is called, the output address is “default”.

-          priority is not used now.

  • Return Value
  •  0               OK
  • Others       Fail

                                 About detail fail type, please reference the LINUX error type define.

 

2.4.26  mas_set_device_desc_ext

  • API Define
  • int mas_set_device_desc(void *handle, mas_aud_device_t  dev,  mas_device_config_t *devConfig);

-          It is used to modify the description of device.  If the action cause output format change, the current playback will be reset(stop=>play).

  • Parameters
  • handle         :  Mediatek audio service handler which is got from mas_create.
  • dev              :  for now only support following 2 kinds device.

 

Figure 2‑13. MAS Set Device Desc value

Note:  Only one device is connected, its description can be modified. BT device is not support now.

  • devConfig     :   device configuration description.

case1:    hw_spk_chmap is NULL   user_spk_chmap is NULL.     => Not support.

case2: hw_spk_chmap is NULL,user_spk_chmap is not NULL=> only config user_spk_chmap user_spk_chmap will checked with last hw_spk_chmap setting. If it is valid, it will be set to device.

case3: hw_spk_chmap is not NULL  user_spk_chmap is NULL=> only config hw_spk_chmap.  hw_spk_chmap will be checked if it is valid. If it is valid, it will be set to device.

                 user_spk_chmap of the device will generated from  hw_spk_chmap.

 case4: both hw_spk_chmap and user_spk_chmap  are not NULL.hw_spk_chmap and user_spk_chmap will be checked if it is valid. If it is valid, they will be set to device.

Note: About detail structure of devConfig, please refer 2.3.25

  •   Return Value
  • 0                OK
  • Others       Fail

     About detail fail type, please reference the LINUX error type define.

 

2.4.27  mas_set_out_mix_format

  • API Define
  • int mas_set_out_mix_format(void *handle, int enable,  mas_chmap_desc_t *channel);

-          It is used to set mix format. And this function is useful when mix out ppc is enabled.

           Because in some cases, PP request special input channel layout.

  • Parameters
  • handle         :  Mediatek audio service handler which is got from mas_create.
  • enable         :  Mix out format enable or not.  1 : enable     0: disable

       Note:  Mas default diable mix format.

  • channel    :    Mix  format channel layout.

 

-          if mix format is disable, the mix channel layout is same with output channel layout.

-          If PPC is enable, PPC must support in and out channel layout same with output

 

-           if mix format is enable, If PPC is enable, PPC must support in channel layout same with    mix,  out channel layout same with output.

             Return Value

· 0                OK

· Others       Fail

 

                                NOTE: About detail fail type, please reference the LINUX error type define.

 

2.4.28  mas_set_spectrum_enable

  • API Define
  • int mas_set_spectrum_enable(void *handle, int enable,  char *addr);

-          It is used to set spectrum function. spectrum is used to calculate current output signal power.

  • Parameters
  • handle  :  Mediatek audio service handler which is got from mas_create.
  • enable  :  Spectrum enable or not.  1 : enable     0: disable.

Note:  Mas default diable spectrum.

  • addr    :    Spectrum output fifo address,  now only support use Linux fifo to transfer spectrum information.

Note: if addr is NULL,  Mas will use default fifo address “/tmp/spectrum_fifo” to output information.

  • Return Value
  •               OK
  • Others       Fail

             About detail fail type, please reference the LINUX error type define.

2.4.29  mas_set_out_block_mode

  • API Define
  • int mas_set_out_block_mode(void *handle, int block);

-          It is used to set output HAL block mode.

  • Parameters
  • handle         :  Mediatek audio service handler which is got from mas_create
  • block           :  block mode.  1 : block  mode   0: non-block mode

 

Note:

-       If use block mode, output HAL will write data to driver by using block method.

-       If use non-block mode, output HAL will write data to driver by using non-block method.

-        If playback application want to get current status, the non-block mode must be set. Or the status get operation will be delayed.

-       If there is no setting change,  MAS default use non-block mode.

 

  •  Return Value
  •               OK
  • Others       Fail

       About detail fail type, please reference the LINUX error type define.

2.5 Sample Code

2.5.1  MAS create and start

?

#include “mas_lib.h”        /* mas  header file include */

  

void *handle = NULL;

int ret;

  

ret = mas_create(&handle);               /* mas create */

if (ret != 0 || handle == NULL)

goto exit;

  

/* We can do some initialization between mas_create() and mas_start() */

/* init master volume, option operation, if not set, mas default master volume is 100 */

ret = mas_set_master_vol(handle, 50);

if (ret != 0)

                goto exit;

  

/* init speaker device’s description, option operation

 if not set , mas default speaker description is 2ch L/R 32bit,  output alsa hardware is “default” */

mas_device_configext_t config;

mas_chmap_desc_t hw_spk;

mas_chmap_desc_t usr_spk;

char *outputaddr = “hw:0,6

  

memset(&config, 0, sizeof(config));

hw_spk.channels = 2;         /* hw speaker is set to 2ch LR */

hw_spk.chmap[0] = MAS_CHMAP_FL;

hw_spk.chmap[1] = MAS_CHMAP_FR;

usr_spk.channels = 2;         /* user speaker is set to 2ch LR */

usr_spk.chmap[0] = MAS_CHMAP_FL;

usr_spk.chmap[1] = MAS_CHMAP_FR;

config.hw_spk_chmap = &hw_spk;

config.user_spk_chmap = &usr_spk;

config.bits = 32/* speaker output bitdepth is 32bit */

config.addr  = outputaddr;  /* mas speaker alsa device address is hw:0,6 */

ret = mas_set_device_desc_ext(handle, MT_AUDIO_OUT_SPEAKER, &config);

if (ret != 0)

                goto exit;

  

/* init output sample rate rule, option operation,   If not set, the default mas rule is MAS_OUT_SR_DYNAMIC_MAIN*/

ret = mas_set_out_samplerate_rule(handle, MAS_OUT_SR_FIX, 48000); /* set fix 48000 output */

if (ret != 0)

                goto exit;

  

/* init mas output buffer rule, option operation, if not set, the default is 20ms period, 40ms kernel buffer,  20ms start threshold */

mas_out_buffer_rule_t rule;

rule.period_time = 20/* set period time is 20ms */

rule.period_num = 4/*  total kernel buffer is 20 * 4 = 80ms */

rule.start_threshold = 0; /* kernel driver start threshold is 20ms */

ret = mas_set_out_buffer_rule(handle,  rule);

if (ret != 0)

                goto exit;

  

/* init ppc enable position, option operation, if not set, all the ppc position is diabled */

/* Note: if this function is not used, please do not set */

ret = mas_ppc_enable(handle, MAS_PPC_MIXER_OUT, 1);          /* enable ppc after mixer out  */

if (ret != 0)

                goto exit;

  

/*  init spectrum function,  option operation, if not set, spectrum function is default disabled */

/* Note: if this function is not used, please do not set */

ret = mas_set_sepctrum_enable(handle, 1,  “/tmp/my_fifo”);   /* enable spectrum */

if (ret != 0)

                goto exit

  

ret = mas_start(handle);                    /* mas start */

if (ret != 0)

                goto exit;

return 0;

exit:

                mas_destroy(handle);

                return ret;

 

2.5.2   MAS stop and destroy

/* make sure there is no any playback,  or stop/destroy will fail */

mas_stop(handle);

mas_destroy(handle);

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐