Audio Playback in brew applications

Source: Internet
Author: User

Brew supports two types of audio formats: midi-based file formats and special encoding audio file formats. Midi-based file formats include. mid ,. DLS .. xmf and. the DLS file is defined by the device and cannot be played by itself. The xmf file combines Midi and DLS for playback. Similar to xmf, the PMD file is a file container that can contain Midi, DLS, and audio in other encoding formats, as well as images, text, led, or Vibration Synchronization information. Encoding audio formats include qcelp, PCM, and ADPCM. qcelp is a speech compression decoder and is not suitable for playing music. PCM is a kind of 16-bit uncompressed waveform sample raw data, which is very suitable for playing music, but the file size is very large. ADPCM only has 1/4 PCM file size, which is suitable for music and sound effects on mobile phones. In terms of sampling rate, qcelp is only a sampling rate of 8 kHz, while PCM supports 4, 8, 11.025, 12, 16, 22.05, 24, 32, 44.1khz, ADPCM supports any collection rate from 4.0 to kHz.

Taking playing a qcp file as an example, playing an audio file is very simple. First, create the imedia interface of aeeclsid_mediaqcp, call imedia_setmediadata () to load the audio file, and then call imedia_play () to play the video.

During loop playback, there is usually a short gap between the end of the file playback and the playback of the file. Brew 3.1.5 and later versions support qcp, PCM, and ADPCM. For example, call imedia_setmediaparm (pimediaqcpobject, mm_parm_play_repeat, repeatcount, 0) and imedia_enablechannelshare () before loading the qcp file, and then call imedia_play () the qcp audio effect can be played cyclically without intervals.

In some cases, mixed audio effects are required. In brew 2.1 and later versions, four MIDI files are mixed, four qcp files are mixed, or four ADPCM files are mixed. It should be noted that the mixed files must be in the same file format, such as all qcp files or all ADPCM files, rather than mixing qcp files with PCM or ADPCM files, only some mobile phones later than 07 years ago (in the Chinese market) began to support mixed playback of different audio format files. The process of audio mixed playback is similar to that of loop playback without gaps. First, create an interface and then load each audio file through imedia_setmediadata, call imedia_enablechannelshare () immediately after creating a media object, and then use imedia_play () for audio mixing. In versions earlier than 3.1.4, imedia_enablechannelshare () may be faulty. In addition, Apis created using aeeclsid_mediamidioutqcp can take both qcp and ADPCM files into account.

Another simple method for audio mixing is to embed all the necessary audio files into a cmx file, and then play only the cmx file. The limitation of this method is that cmx is supported by mobile phones.

The downloadable audio (DLS) is a custom waveform table for MIDI synthesizer. You can use the Midi command to play or stop audio, adjust the volume, and adjust the volume. In cmx 4.4 and later versions, this downloadable audio can also be embedded in. pMD or. xmf files. In Versions later than SDK 3.1.4, you can use the idls API to load or uninstall such downloadable audio. Table 14-2 describes the DLS sound effects and their applicability.

Type
Description
Example
Advantages of DLS
 
Single sound effect
Play Sound effects within the maximum sampling period
Shot Sound t

Opening and Closing sound
You can press the up or down key to determine the sound accuracy.
 
Loop sound effects
Loop playback of a continuous sound effect
The sound of junma and Benz
The audio is quasi-changeable and can be kept in the file.
 
Fragment sound effects
Loop playback of shorter sound effects or Synthesis of New Sound Effects
Sound of disassociation of items, sound of mechanical Engines
Quasi-variable sound, which can be kept in files and can produce more complex sound effects through basic sound effects
 

Table 14-2: DLS sound effects and applicable scenarios

When using idls, you must first create the DLS object:

Ishell_createinstance (m_pishell, aeeclsid_mediadls, (void **) & m_pidls );

Next, set the media data attribute of the DLS file:

Aeemediadata mediadata;

Mediadata. clsdata = mmd_file_name;

Mediadata. pdata = dls_file;

Mediadata. dwsize = 0;

Then initialize the DLS callback function and load the DLS file.

Callback_init (& m_cbdlsload, loaddlscb, (void *) This );

Ireturn = idls_load (m_pidls, & mediadata, & m_cbdlsload, & m_loaddlsret );

If the DLS is global, you can use the imediamidi interface object to play the MIDI file.

Boolean fisglobal = false;

Ireturn = idls_isglobal (m_pidls, & fisglobal );

If (fisglobal ){

Playonemidi (midi_file, & m_pimediamidi );

Return;

}

Because xmf/DLS is not widely used, special tools are required to create and generate such files, such

Faith West Inc.'s "mxmftool" tool.

During the interruption and recovery operations, the application sound must be played again after it is interrupted, but the sound may not be restored on some mobile phones. The main reason for this is that when the mobile phone receives a short message, it will generate a sound prompting the user to receive, and this sound cannot be banned in the application, this is because the short message concerts occupy the chips of audio Resources in the mobile phone. Some mobile phones cannot trigger the evt_app_suspend event when receiving short messages, so the application does not know that the sound used in the application has stopped playing. There are usually two solutions: one is to set the timer and let the application set the music in stages. The following is the processing done by the application in this way:

If (PAPP-> J udgemusicopen) // determine the music to be played

{Musicplayer (Papp, Papp-> M-P isoundplayer, "musicname"); // play the current music

// Continue playing after the music is played

Ishell-set timer (PAPP-> A. M-P ishell, 3000, (pfn1_y) backmusicplay, (void 3) PAPP );}

When the application is interrupted, the operation is isoundplayer_stop (m-pisoundplayer); the operation is

If (PAPP-> J udgemusicopen) // determine the music to be played

Backmusicplay (PAPP-> M-P isoundplayer); // loop playback

Another method is to call a callback function, such as imedia_registernotify or isoundplayer _ registernotify. When the music is interrupted by a short message, the application will receive a prompt in the aee_soundplayer_done or mm_status_done status. Once this status prompt is obtained, it needs to be played again. In special cases, after an application is interrupted, music cannot be played on some mobile phones. These two methods can be used to solve these problems.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/wireless_com/archive/2010/07/18/5744105.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.