Uc/os Examples of applications

Source: Internet
Author: User
//-------------------------------------------------


PCM Player with Real time AMR Codec decode
//
Useing Ucos-ii to build this applications
//
Author:xxc
//
Target Chip:sieko Epson s1c333209
//
version:1.0.0
////////////////////////////////////////////////

////////////////////////////////////////////////
//
//
Shannxi Microvantech Corp.
//
(c) 2004 Copyright by XXC
//
All Rights Reserved
//
//
///////////////////////////////////////////////


#include "includes.h"//For OS
#include "amrglobal.h"//For AMR Codec
#include "dec_com.h"//For AMR decode


#define TASK_STK_SIZE 512

#define SERIAL_FRAMESIZE (1+MAX_SERIAL_SIZE+5)

void TimerTask (void* data); Initlize Task,only Run Once

void Playtask (void* pdata); Preplay Task,use for filling play buffer
With first time and start playing.
void WorkTask1 (void* pdata); Background task. Use for filling play date
When the DAC finished played the dates.

void Amr_speech_decode_proc (short *en475_buf, short *synth);
extern const Char en475_buf[];

OS_STK Timerstk[task_stk_size];
OS_STK Playstk[task_stk_size];
OS_STK Workstk1[task_stk_size];

void Main ()
{
Osinit ();
Ostaskcreate (TimerTask, (void*) 0,&timerstk[task_stk_size-1],5);
Ostaskcreate (Playtask, (void*) 0,&playstk[task_stk_size-1],7);
Ostaskcreate (WorkTask1, (void*) 0,&workstk1[task_stk_size-1],9);
Osstart ();

}

void TimerTask (void *pdata)
{

pdata = pdata;

Os_enter_critical ();

* ((int8u*) 0x48205) = 0;
* ((int32u*) 0x48200) = idma_start_address;
* ((int8u*) 0x48205) = 1;
Dacd_initialize ();
Dacd_setsamplingmode (8000, 1, 16);
Dacd_setheadphonevolume (60, 60);

Os_exit_critical ();

Stop_16timer (T16P_PRUN1_ADDR);
Init_16timer1 ();
Run_16timer (T16P_PRUN1_ADDR);

Ostasksuspend (9);
Ostasksuspend (5); Switch to play task
}

void Playtask (void* pdata)
{
INT32U i;
Int8u J;
int16u index;
int8u* PBuf;
int16u* serial = (int16u*) en475_buf;
pdata = pdata;
for (;;)
{
Speech_decode_frame_init ();
i=0;
j = 1;
Run_16timer (T16P_PRUN1_ADDR);
while (I < 8)
{
PBuf = Dacd_getnextbuffer ();
if (PBuf! = 0)
{
Stop_16timer (T16P_PRUN1_ADDR);
Amr_speech_decode_proc (Serial+i*serial_framesize, (short *) pBuf);
i++;
Amr_speech_decode_proc (Serial+i*serial_framesize, (short *) pbuf+160);
i++;
Amr_speech_decode_proc (Serial+i*serial_framesize, (short *) pbuf+320);
i++;
Amr_speech_decode_proc (Serial+i*serial_framesize, (short *) pbuf+480);
i++;
PBuf = Dacd_acknowledge (640);
Run_16timer (T16P_PRUN1_ADDR);
ostimedly (1);
}
}
Dacd_startplay ();
Ostaskresume (9);
Ostasksuspend (7);
}
}

void WorkTask1 (void* pdata)
{
INT32U i;
int16u index;
int8u* PBuf;
int16u* serial = (int16u*) en475_buf;

pdata = pdata;
for (;;)
{
i = 8;
while (I<framesum)
{
PBuf = Dacd_getnextbuffer ();
if (PBuf! = 0)
{
Stop_16timer (T16P_PRUN1_ADDR);
Amr_speech_decode_proc (Serial+i*serial_framesize, (short *) pBuf);
i++;
Amr_speech_decode_proc (Serial+i*serial_framesize, (short *) pbuf+160);
i++;
Amr_speech_decode_proc (Serial+i*serial_framesize, (short *) pbuf+320);
i++;
Amr_speech_decode_proc (Serial+i*serial_framesize, (short *) pbuf+480);
i++;
PBuf = Dacd_acknowledge (640);
Run_16timer (T16P_PRUN1_ADDR);
}
ostimedly (1);
}
Ostaskresume (7);
}
}

void Amr_speech_decode_proc (short *en475_buf, short *synth)
{
int16u param[max_prm_size+1]={0};
Word16 Az_dec[az_size];

BITS2PRM (en475_buf+1, param);
Decoder_amr (&g_decoder_amrstate, &g_ec_gain_p_st, &g_ec_gain_c_st, param, synth, az_dec);
Post_filter (& (G_post_state.synth_buf[m]), G_post_state.res2, G_post_state.mem_syn_pst, synth, Az_dec);
Post_process (synth, &g_posthp_state);
}

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.