Use the audio engine Mita to read the source code of the cue File

Source: Internet
Author: User

# Include ".../../include/Mita. H"/** <@ brief Mita SDK header */
# Ifdef _ debug
# Pragma comment (Lib, ".../../library/mitad. lib ")
# Else
# Pragma comment (Lib, ".../../library/Mita. lib ")
# Endif

# Include <windows. h>
# Include <stdio. h>
# Include <conio. h>
# Include <math. h>

# Pragma warning (push)
# Pragma warning (Disable: 4996)

Mita_static
Mita_inline
Mita_void
Mita_checkerror (mita_void)
{
Mita_error lasterror = mita_getlasterror ();
If (lasterror! = Mita_error_ OK)
{
Printf ("error: MITA framework error with % u codes \ n", lasterror );
Exit (lasterror );
}
}

Mita_static
Mita_inline
Mita_byte
Mita_enterkey (mita_void)
{
Mita_int32 key = 0xff;
Do
{
If (kbhit ())
{
Key = getch ();
Break;
}
Sleep (10 );
} While (1 );
If (Key> = 'A' & Key <= 'Z ')
Key-= 32;
Return key;
}

//////////////////////////////////////// //////////////////////////////////
// Channelmask must has channel number in high 8 bits.
// | 00000000 | mmmmmm Mmmmmmmm |
// Nums channelmask
// How to set number?
// Mita_chnfmt_setnum (mask, 2)
// Also you can use mita_guesschannelmode.
//
// The channel number must equal with channel mask.
// Channelmask = mita_cp_front_left | mita_cp_front_right; // use two speaker
// Mita_chnfmt_setnum (channelmask, 2); // set 2
//
Mita_static
Mita_inline
Mita_houtput
Mita_createdefaultoutput (mita_hinstance hinstance, mita_dword channelmask)
{
Mita_houtput houtput;
Mita_hdevice hdevice;
Mita_deviceparam Param;
Mita_size I, N;
Mita_deviceinfo DevInfo;
Mita_byte key = 'a ';
Mita_dword IDs [10];
Mita_byte maxids = 0;

Mita_ins_createobject (hinstance, & iid_devwinmme, & hdevice );
Mita_checkerror ();

Mita_device_getdevicenums (hdevice, & N );
Mita_checkerror ();

Printf ("\ nselect A output device: \ n ");
_ Try_again:
Key = 'a ';
For (I = 0; I <n; I ++)
{
Mita_device_getdevice (hdevice, I, & DevInfo );
Mita_checkerror ();
If (DevInfo. type = mita_ct_output)
{
IDS [key-'a'] = Devinfo. devid;
Printf ("[% C] device % s [% F-% F] \ n", key, mita_text_tosystems (DevInfo. devname, mita_tct_default), DevInfo. latency [0], DevInfo. latency [1]);
Key ++;
Maxids ++;
}
}
Key = mita_enterkey ()-'A ';
If (Key> = maxids)
{
Printf ("error: Invalid input keys, please try again. \ n ");
Goto _ try_again;
}

Param. Callback = mita_null;
Param. callbackhandle = mita_null;
Param. Customer = mita_null;/** <@ brief for future use */
Param. channelfmt. Mask = channelmask;/** <@ brief the mask of channels .*/
Param. channelfmt. sfmt = mita_sdt_f32;/** <@ brief float32 sample */
Param. channelfmt. SPS = 4410020.f;/** <@ brief 44.1 kHz */
Param. latency = 0.1f;/*** <@ brief 100 MS latency */
Param. type = mita_ct_output;/** <@ brief for output .*/
Param. devid = IDs [Key];/** <@ brief the ID of device */

Mita_output_createbydevice (hinstance, hdevice, & Param, mita_false, & houtput );
Mita_checkerror ();

Return houtput;
}

Mita_static
Mita_inline
Mita_void
Mita_printdecsupportexts (mita_hinstance hinstance)
{
Mita_hfactory decfactory;
Mita_hobjectlist declist;
Mita_size I, n, J, JN;
Mita_afd AFD;
Mita_hdecoder hdecoder;
Mita_ins_getfactory (hinstance, mita_mt_decoder, & decfactory );
Mita_checkerror ();
Mita_objectlist_build (hinstance, decfactory, mita_false, & declist );
Mita_checkerror ();
Mita_objectlist_count (declist, & N );
For (I = 0; I <n; I ++)
{
Mita_objectlist_get (declist, I, & hdecoder );
Mita_decoder_getfiledescribenums (hdecoder, & JN );
For (j = 0; j <JN; j ++)
{
Mita_decoder_getfiledescribe (hdecoder, J, & AFD );
Printf ("% s;", mita_text_tosystems (AFD. Ext, mita_tct_default ));
}
}
Printf ("\ n ");
Mita_closehandle (declist );
}

Mita_static
Mita_inline
Mita_void
Mita_printsoundarray (mita_harray hitemarray)
{
Mita_sizei, N;
Mita_hsoundhsounditem;
Mita_wcharszpath [mita_maxpath];
Mita_uuidcoderguid;

Printf ("\ n ");
N = mita_array_getcount (hitemarray );
For (I = 0; I <n; I ++)
{
Mita_array_get (hitemarray, I, & hsounditem );
Mita_sound_getpath (hsounditem, szpath, mita_maxpath );
Mita_sound_getcoderguid (hsounditem, & coderguid );
Printf ("Path: % s \ n", mita_text_tosystems (szpath, mita_tct_default ));
}
}

Mita_static
Mita_inline
Mita_void
Mita_deletesoundarray (mita_harray hitemarray)
{
Mita_sizei, N;
Mita_hsoundhsounditem;

N = mita_array_getcount (hitemarray );
For (I = 0; I <n; I ++)
{
Mita_array_get (hitemarray, I, & hsounditem );
Mita_closehandle (hsounditem );
}
Mita_closehandle (hitemarray );
}

Void main (void)
{
Mita_hinstance ginstance = mita_null;
Mita_char szversion [64];
Mita_size plugincount = 0;
Mita_hinput hcuritem = mita_null;
Mita_houtput houtput;
Mita_hengine hengine;
Mita_dword channelmask;
Mita_byte key = 0;
Mita_time curtime;
Mita_time durtime;
Mita_dword cur_ms, dur_ms;
Mita_channelformat channelfmt;
Mita_status status;
Mita_harray hitemarray = mita_null;
Mita_sizecuritemindex = 0;
Mita_sizetotalitem = 0;

Printf (";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; \ n ");
Printf ("; Copyright (c) Hangzhou citrus Technology Co., Ltd. 2008-2011. All Rights Reserved .;; \ N ");
Printf (";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; \ n ");
Printf ("; decode cue example; \ n ");
Printf (";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; \ n ");

//////////////////////////////////////// //////////////////////////////////
// 1. Create a global instance handle.
Ginstance = mita_initialize (mita_null );
Mita_checkerror ();

//////////////////////////////////////// //////////////////////////////////
// 2. Check SDK version, this was not necessary.
Mita_getversionstringa (szversion, 64 );
Mita_checkerror ();
Printf ("; Mita: Version % s \ n", szversion );

//////////////////////////////////////// //////////////////////////////////
// 3. Load all existed plugins.
Mita_ins_loadpluginfromdir (ginstance, l ".../../plugins", & plugincount );
Mita_checkerror ();
Printf ("; Mita: Load % u plugins \ n", plugincount );
Printf ("; support:; \ n ");
Mita_printdecsupportexts (ginstance );
Printf (";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; \ n ");

//////////////////////////////////////// //////////////////////////////////
// 4. Create engine object
Mita_engine_create (ginstance, mita_engineflag_checkprepare | mita_engineflag_checkrender, & hengine );
Mita_checkerror ();

//////////////////////////////////////// //////////////////////////////////
// 5. Create output source
Mita_guesschannelmode (8, & channelmask );
Houtput = mita_createdefaultoutput (ginstance, channelmask );

//////////////////////////////////////// //////////////////////////////////
// 6. Add source to engine.
Mita_engine_addsource (hengine, houtput );
Mita_checkerror ();
Mita_output_startup (houtput );
Mita_checkerror ();

//////////////////////////////////////// //////////////////////////////////
// 7. Load Input Source
{
Mita_paramparsesong Param;

Param. dwtagflag = mita_tagread_none;
Param. hdecoderchain = mita_null;
Param. hinstance = ginstance;
Param. hitemarray = mita_null;
Param. hstream = mita_null;
Param. nstreambeginpos = 0;
Param. lppath = l ".. \ media \ test. Cue ";

Mita_ins_parsesong (& PARAM );
Mita_checkerror ();

Hitemarray = Param. hitemarray;
}
Totalitem = mita_array_getcount (hitemarray );
{
Mita_hsound hsound;

//////////////////////////////////////// /////////////
// Prevent mita_engine_deletesource from automatically removing hsound objects
For (curitemindex = 0; curitemindex <totalitem; curitemindex ++)
{
Mita_array_get (hitemarray, curitemindex, & hsound );
Mita_sound_readonly (hsound, mita_true );
}
Curitemindex = 0;

Mita_array_get (hitemarray, curitemindex, & hsound );
Mita_input_loadbysound (ginstance, hsound, & hcuritem );
Mita_engine_addsource (hengine, hcuritem );
Mita_input_play (hcuritem, mita_null );
}

Printf ("\ n ");
Printf ("Press o to Prev sound. \ n ");
Printf ("Press P to next sound. \ n ");
Printf ("Press ESC to exit \ n ");
Do
{
If (kbhit ())
{
Key = getch ();

Switch (key)
{
Case 'O ':
Case 'O ':
{
//////////////////////////////////////// //////////
// To Prev
Mita_hsound hsound;
Mita_engine_deletesource (hengine, hcuritem); // delete current source
Curitemindex = (CurItemIndex-1 + totalitem) % totalitem; // move to Prev Source
Mita_array_get (hitemarray, curitemindex, & hsound );
Mita_input_loadbysound (ginstance, hsound, & hcuritem); // load New Source
Mita_engine_addsource (hengine, hcuritem );
Mita_input_play (hcuritem, mita_null );
} Break;
Case 'p ':
Case 'p ':
{
//////////////////////////////////////// //////////
// To next
Mita_hsound hsound;
Mita_engine_deletesource (hengine, hcuritem); // delete current source
Curitemindex = (curitemindex + 1) % totalitem; // move to next Source
Mita_array_get (hitemarray, curitemindex, & hsound );
Mita_input_loadbysound (ginstance, hsound, & hcuritem); // load New Source
Mita_engine_addsource (hengine, hcuritem );
Mita_input_play (hcuritem, mita_null );
} Break;
}
}

Mita_source_getstatus (hcuritem, & status );
Mita_source_getcurtime (hcuritem, & curtime );
Mita_input_getduration (hcuritem, & durtime );
Mita_input_getchannelformat (hcuritem, & channelfmt );
Mita_time_cvt (& channelfmt, & curtime, mita_timeunit_micrsecond, & curtime );
Mita_time_cvt (& channelfmt, & durtime, mita_timeunit_micrsecond, & durtime );
Cur_ms = (mita_dword) mita_time_getdata (curtime );
Dur_ms = (mita_dword) mita_time_getdata (durtime );

Printf ("% 10 S % 02u: % 02u: % 02u/% 02u: % 02u: % 02u [% u Channels] [% u/% u] \ r ", status = mita_status_running? "Playing" :( status = mita_status_pause? "Pause": "Stop "),
Cur_ms/1000/60,
Cur_ms/1000% 60,
Cur_ms/10% 100,
Dur_ms/1000/60,
Dur_ms/1000% 60,
Dur_ms/10% 100,
Mita_chnfmt_getnum (channelfmt. Mask), curitemindex + 1, totalitem );
If (status = mita_status_idle)
{
//////////////////////////////////////// //////////
// To next
Mita_hsound hsound;
Mita_engine_deletesource (hengine, hcuritem); // delete current source
Curitemindex = (curitemindex + 1) % totalitem; // move to next Source
Mita_array_get (hitemarray, curitemindex, & hsound );
Mita_input_loadbysound (ginstance, hsound, & hcuritem); // load New Source
Mita_engine_addsource (hengine, hcuritem );
Mita_input_play (hcuritem, mita_null );
}

Sleep (10 );
} While (key! = 27 );

Mita_engine_deletesource (hengine, hcuritem );
Mita_deletesoundarray (hitemarray );
Mita_closehandle (hengine); // release engine object
Mita_closehandle (ginstance); // release global instance handle.
}

# Pragma warning (POP)

Related Article

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.