22
19, Innovation Road 1 Science-Based Industrial Park Hsin-Chu Taiwan R.O.C. % 886-3-578-6005 886-3-578-4418 www.sunplus.com.tw Sound Library User’s Manual V1.1.0 – January 02, 2007

Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

19, Innovation Road 1 • Science-Based Industrial Park • Hsin-Chu • Taiwan • R.O.C. % 886-3-578-6005 886-3-578-4418 www.sunplus.com.tw

Sound Library User’s Manual V1.1.0 – January 02, 2007

Page 2: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 2 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

Table of Content PAGE

Sound Library User’s Manual .................................................................................................................................................. 1

1 Function List ..................................................................................................................................................................... 4

2 Application Interface for Near_NoOS Platform............................................................................................................... 5

2.1 SACM_Initial............................................................................................................................................................ 5

2.2 SACM_Codec............................................................................................................................................................ 5

2.3 SACM_Volume ......................................................................................................................................................... 5

2.4 SACM_Speed............................................................................................................................................................ 6

2.5 User_SetStartAddrManual ...................................................................................................................................... 6

2.6 USER_SetRECStartAddr ........................................................................................................................................ 6

2.7 SACM_Play............................................................................................................................................................... 7

2.8 SACM_ServiceLoop................................................................................................................................................. 8

2.9 SACM_Pause ............................................................................................................................................................ 8

2.10 SACM_Resume......................................................................................................................................................... 8

2.11 SACM_Stop............................................................................................................................................................... 9

2.12 SACM_Status............................................................................................................................................................ 9

2.13 SACM_DVR1800_BITRATE .................................................................................................................................. 9

2.14 SACM_Rec.............................................................................................................................................................. 10

2.15 SACM_MP3_SetFS .................................................................................................................................................11

2.16 SACM_MP3_Get_Time ..........................................................................................................................................11

2.17 MP3_EQMode ........................................................................................................................................................ 12

3 SpecialNotes For NoOS Platform ................................................................................................................................... 13

Page 3: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 3 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

Revision History

Revision Date By Remark V1.1.0 2007-01-02 Xiaolei The First Release For 2002 Platform Use V1.0.4 2005-12-27 xiaolei Add the API for far platform V1.0.3 xiaolei Add the No_Len A1600 skip play, Modify the Codec Type of the

A1600Skip play API V1.0.2 2005/10/19 guili Add A1600 Skip play API;

Add DVR pause, resume V1.0.2 2005/10/13 guili Add ETTS and CTTS and DVR API V1.0.1 2005/06/15 guili Add C_CODEC_MS02 V1.0.0 2005/06/01 guili First release for SPL162001

Page 4: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 4 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

1 Function List

Index syntax 1 void SACM_Initial(); 2 void SACM_ServiceLoop(void); 3 void SACM_Play(int Speech index, int Channel ,int Ramp); 4 void SACM_Stop(void); 5 void SACM_Pause(void); 6 void SACM_Resume(void); 7 void SACM_Volume(int volume); 8 unsigned int SACM_Status(void); 9 void SACM_Speed(int speed); 10 void SACM_Codec(int codec); 11 void SACM_Codec(int codec); 12 void SACM_Rec(int RceMonitor, int bit_rate); 13 void SACM_DVR1800_BITRATE(int BitRate); 14 void SACM_MP3_SetFS(void); 15 void USER_SetStartAddr(int index); 16 void USER_SetRECStartAddr(long address); 17 int SACM_MP3_Get_Time(void); 18 Void MP3_EQMode(int ModeType);

Page 5: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 5 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

2 Application Interface for Near_NoOS Platform

2.1 SACM_Initial

API Name SACM_Initial(void) Function Kernel variables initialization and calls HW initial Description Initial SACM Speech.

C SACM_API.h Header File

ASM

C void SACM_Initial(void); Syntax ASM

Parameters void

Return Values None

Remarks This Function must be called when user play the SACM speech or use the record function.

2.2 SACM_Codec

API Name SACM_Codec(int codec) Function decode speech type select Description decode speech type select

C SACM_API.h Header File

ASM

C void SACM_Codec(int codec); Syntax

ASM

Parameters codec: depend on how many speech used. Generalplus suggest programmers use constant value that defined in ahgorithm.h

Return Values

Remarks Set the speech type

2.3 SACM_Volume

API Name SACM_Volume(int volume)

Function speech volume setup

Description speech volume setup, setup the volume of the speech

C SACM_API.h Header File

ASM

C void SACM_Volume(int volume); Syntax

ASM

Parameters volume: 0(mute) ~ 15(max)

Return Values void

Remarks

Page 6: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 6 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

2.4 SACM_Speed

API Name SACM_Speed(int speed) Function speech play speed setup

Description speech play speed setup

C SACM_API.h Header File

ASM

C void SACM_Speed(int speed); Syntax

ASM

Parameters speed: 0(slowest) ~ 24(fastest)

Return Values If the current CodecID is MIDI(MS01 or MS02), the speed setting is invalid.

2.5 User_SetStartAddrManual

API Name User_SetStartAddrManual Function Speech source data address defined by users

Description Speech source data address defined by users

C SACM_API.h Header File

ASM

C void User_SetStartAddrManual (long address); Syntax

ASM

Parameters index: speech index.

Return Values None

Remarks This Function is used when play the resource in Memory, For example:

{

User_SetStartAddrManual(LB2LP(_RES_VERD24M_MP3_sa));

SACM_Play(SpeechIndex, DAC1+DAC2, 0);

}

2.6 USER_SetRECStartAddr

API Name USER_SetRECStartAddr

Function DVR encoded data store address defined by users.

Description DVR encoded data store address defined by users.

C SACM_API.h Header File

ASM

C void USER_SetRECStartAddr(long address); Syntax

ASM

Page 7: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 7 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

Parameters address: encoded data store address.

Return Values None

Remarks This Function is used for recording into Memory, For example:

{

USER_SetRECStartAddr(RECStartAddr + 2);

SACM_Rec(RecMonitorOff, BIT_RATE);

}

2.7 SACM_Play

API Name SACM_Play(int Speech index, int Channel ,int Ramp) Function

Description Release Sound resource and ISR

C SACM_API.h Header File

ASM

C void SACM_Play(int Speech index, int Channel ,int Ramp); Syntax

ASM

Parameters Parameter: Speech index: -1 : Mamual mode

0 - max index : Auto mode Channel: 1: DAC1 on 2: DAC2 on 3: DAC1,2 on Ramp: 0: ramp up/down off 1: ramp up on 2: ramp down on 3: ramp up/down on

Return Values None

Remarks About Speech index: When you play from Fat, you should choose Mamual mode; When you play from memory, you should choose Auto mode.

Examples 1、 Play from Memory: {

... CodecType = C_CODEC_A1800;

SACM_Codec(CodecType);

SACM_Play(SpeechIndex, DAC1+DAC2 ,0);

} 2、 Play from FAT: {

Page 8: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 8 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

... CodecType = C_CODEC_AUDIO1800; FileHandle = open((LPSTR)("A:\\dunk2_16.a18"),O_RDWR); SACM_Codec(CodecType); Fat_SetStartAddr(LB2LP(NFAT_DS_GetData)); SACM_Play(Manual_Mode_Index,DAC1+DAC2,0); ...

}

2.8 SACM_ServiceLoop

API Name SACM_ServiceLoop

Function Decode the resource datas

Description decode bit stream(or encoded data) C SACM_API.h Header File

ASM

C void SACM_ServiceLoop(void); Syntax

ASM

Parameters None

Return Values None

Remarks

2.9 SACM_Pause

API Name SACM_Pause(void) Function speech pause

Description Pause the current speech

C SACM_API.h Header File

ASM

C void SACM_Pause(void); Syntax

ASM

Parameters None

Return Values None Remarks None

2.10 SACM_Resume

API Name SACM_Resume(void) Function speech resume

Description Speech resume, Resume the speech paused before long.

C SACM_API.h Header File

ASM

Syntax C void SACM_Resume(void);

Page 9: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 9 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

ASM

Parameters

Return Values None

Remarks

2.11 SACM_Stop

API Name SACM_Stop(void) Function speech stop

Description speech stop, stop the current speech

C SACM_API.h Header File

ASM

C void SACM_Stop(void); Syntax

ASM

Parameters None

Return Values None

2.12 SACM_Status

API Name SACM_Status(void)

Function Get current status

Description Get current status, is stop, or playing, or pause.

C SACM_API.h Header File

ASM

C unsigned int SACM_Status(void); Syntax

ASM

Parameters None

Return Values current status

Remarks Return value:

C_Snd_Stop(0x0000): sound play or record stop; C_Snd_Playing(0x0001): sound playing;

C_Snd_DVRing(0x0002): sound recording;

C_Snd_Pause(0x0004): sound play or record pause.

2.13 SACM_DVR1800_BITRATE

API Name SACM_DVR1800_BITRATE

Function setup DVR1800 bit rate

Description setup DVR1800 bit rate

C SACM_API.h Header File

ASM

Syntax C void SACM_DVR1800_BITRATE(int BitRate);

Page 10: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 10 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

ASM

Parameters BitRate: DVR1800 can support bit rate from 4.8K to 32K bps. From 4.8K to 12K bps, each step is 800bps. From 12K to 32K bps sach step is 4K bps. 4800bps, 5600bps, 6400bps, 7200bps, 8000bps, 8800bps, 9600bps, 10.4kbps,

11.2kbps, 12kbps, 16kbps, 20kbps, 24kbps, 28kbps, 32kbps.

Return Values

2.14 SACM_Rec

API Name SACM_Rec(int RceMonitor, int bit_rate) Function speech DVR record start Description speech DVR record start, start to record to memory

C SACM_API.h Header File

ASM

C void SACM_Rec(int RceMonitor, int bit_rate); Syntax

ASM

Parameters RceMonitor: 0 off 1 on bit_rate: // DVR 4800 bit rate//SampleRate 16 KHz #define BIT_RATE_32K 0 #define BIT_RATE_36K 1 #define BIT_RATE_40K 2 #define BIT_RATE_44K 3 #define BIT_RATE_48K 4 #define BIT_RATE_52K 5 #define BIT_RATE_56K 6 //DVR1600 bit rate://SampleRate 8 KHz #define BIT_RATE_10K 0 #define BIT_RATE_12K 1 #define BIT_RATE_14K 2 #define BIT_RATE_16K 3 #define BIT_RATE_20K 4 #define BIT_RATE_24K 5

Return Values None

Remarks

Examples 1. Record to Memory:

{

...

CodecType = C_CODEC_DVR4800;

SACM_Codec(CodecType);

USER_SetRECStartAddr(RECStartAddr + 2);

SACM_Rec(RecMonitorOff,BIT_RATE);

Page 11: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 11 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

}

2. Record to FAT:

{

...

FileHandle = open((LPSTR)("A:\\REC.a48"),O_CREAT|O_RDWR);

stat((LPSTR)("A:\\REC.a48"),&filestatus);

CodecType = C_CODEC_DVR4800;

SACM_Codec(CodecType);

Fat_SetStartAddr(LB2LP(NFAT_DS_WriteData));

write(FileHandle,(long)Buffer<<1,4);

SACM_Rec(RecMonitorOff,BIT_RATE);

...

}

2.15 SACM_MP3_SetFS

API Name SACM_MP3_SetFS

Function Get MP3 bit rate, sample rate information of MP3 source data. Before playing MP3.

Description Get MP3 bit rate, sample rate information of MP3 source data. Before playing MP3.

C SACM_API.h Header File

ASM

C void SACM_MP3_SetFS(void); Syntax

ASM

Parameters None

Return Values None

Remarks programmers should call this function first before play MP3.

2.16 SACM_MP3_Get_Time

API Name SACM_MP3_Get_Time

Function Get the MP3 current play time.

Description Get the MP3 current play time.

C SACM_API.h Header File

ASM

C int SACM_MP3_Get_Time(void); Syntax

ASM

Parameters No input parameter.

Return Values The current MP3 playtime, the unit is second

Page 12: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 12 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

2.17 MP3_EQMode

API Name MP3_EQMode

Function Set the EQ Mode of MP3.

Description Set the EQ Mode of MP3.

C SACM_API.h Header File

ASM

C Void MP3_EQMode(int ModeType); Syntax

ASM

Parameters The EQ Mode table is described as follows:

0. Reset

1. Rock

2. Classical

3. Pop

4. Jazz

5. Folk

6. Disco

7. Reggae

8. Soft Rock

9. New Age

Return Values None

Page 13: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 13 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

3 SpecialNotes For NoOS Platform

1、 SACM WithoutOS 的实现框图:

1.1 Play:

如上图所示,目前 Demo 为后台解码。

实现函数调用流程(SACM_Codec 以 A1800 为例)如下图所示:

如下图所示,当 IRQ0 中断到时,执行 Put 数据 Out 的操作,将 DAC_Out_Buffer

里面的数据送到 CHA,CHB 的 FIFO 里播放出去,执行完后会修改 PC 和 SR 的指针然后去

执行 F_SACM_ServiceLoop,真正的 reti 其实是 F_SACM_ServiceLoop 的“retf”,在

F_SACM_ServiceLoop 里解码,在解码后 Speech Kernel 会调用 Get Data 函数填充

Decode_In_Buffer,目前 Demo 中是通过直接读文件的方法填充的,这样的后台操作同

时保证了 Decode 和 Get Data 的实时性。

另外,在中断处理中的一个时间问题:

目前 Demo 中设置的 DACFIFO 为 8,在 Play (以 A1800 的 16KSampleRate 为例)的时

候进入中断的频率为 8/16000 = 500us,那么为保证声音的连续性和解码的实时性,其

他中断(在不允许中断嵌套模式下)的处理时间应该小于 500us。

DAC

Nand or SD

or Mem

ory

Memory

Decoder

Buffe

r1

DAC_Out

Buffe

r0

Decode_InDecode_PTR

Play_P

TR

Speed_Control

Decode_OutDecode_In_PTR

Page 14: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 14 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

IRQ0

OR

SACM_Initial

CodecType = C_CODEC_AUDIO1800SACM_Codec(CodecType)

SACM_Play

User_SetStartAddrManual(RES_Address)

SACM_Volume(VolumeIndex)SACM_Speed(SpeedIndex)

Main_Loop Process

OutPut the data In IRQ(call F_ISR_Service_SACM_DAC)

PC = offset F_SACM_ServiceLoopSR = seg F_SACM_ServiceLoop

Push PC, SR to [sp]Reti

Decode when The WORK Flag Is setted

(F_SACM_ServiceLoop)

Fat_SetStartAddr(LB2LP(NFAT_DS_GetData))

1.2 Record:

如上图所示,Demo 中为后台 Encode,Encode_Out_Buffer 后的 Ping_Pang_Buffer

(Ping_Pang_Buffer 的意思是两个 Buffer 交替操作:Buffer1 执行动作 A时,Buffer2

做动作 B,等到两个 Buffer 做完各自的动作后再交换过来,Buffer1 做动作 B, Buffer2

做动作A;具体到Speech中在此处的用法是:当Encode_Out_Buffer的数据写到Buffer1

Buffe

r1

ADC Encoder

R_S

AC

M_A

DC

_In_

Buf

fer

SD or N

and or Mem

ory

Buf

fer0

R_S

AC

M_E

ncod

e_O

ut_

Buf

fer

R_SACM_ADC_In_PTR_Rec

Ping_Pang_Buffer

Page 15: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 15 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

时,将 Buffer2 里面的数据写到文件系统中去;当 Encode_Out_Buffer 的数据写到

Buffer2时,则将Buffer1里面的数据写到文件系统中)为缓冲Buffer(RecordFATBuffer,

用汇编定义在 System.asm 文件中,因为在录音时不可能有 MP3 播放,所以和 MP3 的

ReservedRAM 可以复用),这样也避免了频繁的对文件的写操作,保证了 Encode 的实时

性。但是,从缓冲 Buffer 写到外部存储器里时有一个时间的问题:

Encode_Out 里的数据不断的写到 Ping_Pang_Buffer,当一个 Bufffer 写满时就应

该调用一次写文件的操作并把 Buffer 里的数据写入文件,那么应该保证在填满一个缓

冲 Buffer(Demo 里为 1024)的时间(以 DVR1800 32Kbps 为例, 每压缩一桢需要 20ms, 一

桢 40 个 words, 压缩 1024words 的时间需要 20 * 1024/40 = 512ms)内要把上个 Buffer

里面的录音数据写入外部存储器,这就要求在主函数里至少要在 512ms 内调用一次写

Nand 的函数(Nand_WriteFAT_Rec())。

录音实现调用函数如下图所示:

如图所示,进入中断 IRQ1 后去将 ADC_FIFO 里面的数据读到 ADC_In_Buffer 里面,

然后修改 PC, SR 的指针去执行 F_SACM_ServiceLoop 函数,当一个 ADC_In_Buffer 填满

后就会执行 Encode 的动作,Speech Kernel 把解码后的数据放到 Encode_Out_Buffer

里面,在 main_Loop 里面会执行 Nand_WriteFAT_Rec()将 Encode_Out_Buffer 里面的数

据写入 FAT。

IRQ1

SACM_Initial

CodecType = C_CODEC_AUDIO1800SACM_Codec(CodecType)

SACM_Rec

USER_SetRECStartAddr(RECStartAddr)OR

Fat_SetStartAddr(LB2LP(NFAT_DS_WriteData_Rec))

Main_Loop Process

Nand_WriteFAT_Rec()

Get Data from ADC(call F_ISR_Service_SACM_ADC)

PC = offset F_SACM_ServiceLoopSR = seg F_SACM_ServiceLoop

Push PC, SR to [sp]Reti

Eecode when The WORK Flag Is setted

(F_SACM_ServiceLoop)

Page 16: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 16 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

2、About SoundWithoutOS ProjectTree:

SoundWithoutOS 的工程中 Sound 模组主要包含 API_Code, Customer_Code,

HW_Code(HardWare_Code), User_Code 和 MP3_Code 几个文件夹,这些文件夹的定义都与

其内部文件的内容有关,主要包含内容如下:

Page 17: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 17 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

API_Code

MP3_Code(MP3 Play

Function Demo Code)

User_Code

Customer_Code

HW_Code

供用户调用的一些基

本函数API接口SACM_API.asm

Sound

user_sacm.asm

sacm.asm

FS_DS.C

SACM_Decode.asm供API调用的

Decode&Encode函数

供用户写的对

FS(FileSystem)的读写

操作函数

直接对硬体寄存器设置

的函数

汇编语言的GetData和PutData函数

PlayList.c

GetFileInf.c

MP3的相关信息获取函

MP3的上层Play API Demo函数

Include Files

algorithm.h(algorithm.inc)

sacm_decode.inc

SACM_Constant.inc

SACM_API.h(SACM_API.inc)

Sacm.h(sacm.inc)

各种算法类型(Speech Type)及支持算法的宏开关定义文件,在这

个文件里选择支持的算法

各种算法本身的Kernal函数声明文件

各种算法用到的公共宏

定义和API函数的声明

文件

常量(Buffer长度, SACM状态等)的宏定义文件, 在这个文件里可以看到定义的Decode_Work,

Decode_End, Decode_ODD和C_SACM_PLAY,

C_SACM_STOP等状态变量的定义

与Decode&Encode相关

的API和全局变量的声

明文件

SACM_Decode_Ram.inc

Speech全局变量的定义文件,在这个文

件里可以看到SACM具体用到了多少个

全局变量和分别是什么及其地址

sacmdrv.inc硬体操作相关和驱动函

数声明文件

Page 18: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 18 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

3、算法移植使用步骤(以 DVR1800 的 Rec&Play FAT 先录音后放音为例,具体见 Demo 程

序):

如 2中文件架构图所示,User 需要将对应的 Sound 目录和 Include\Speech 目录加

到 User 的工程中:

将 Demo 工程中的.\Component\Sound 文件夹放在 User 的 Project File 下面作为

一个单独的文件夹;

将 Demo 工程下的.\Component\Include\speech 文件夹放在 User Project File 路

径下面的某个文件夹内(例如系统的.\include 路径下,这里会有 FS, SDC 或者系统所需

要的其他模组的头文件);

如果用到 DVR520 等一些在 2002MaskROM 程序中没有的算法,则需要将 Demo 工程中

的.\Component\Lib\SACM_Lib\DVR520的算法lib也加到User Project File对应的lib

目录下面。

由于 Demo 工程中的头文件包含是以相对路径的方式包含的,所以需要在 User 工程

中做以下设置(如下图中红线圈点处),在 User 工程的 Setting 中将 speech 的头文件路

径设置正确。

如果 User 系统没有用到 MP3,就可以将 Sound\MP3_Code 文件夹和 Include\MP3.h

拿掉。

Page 19: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 19 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

在文件都 Copy 齐全之后要注意一些 Speech 全局变量的定义:将 Demo 中 System.asm

的一些 Speech全局变量的定义和用于 Speech部分的程序 Copy到用户的 System.asm文

件中;

中断函数也要 Copy 到 User 的中断处理文件(isr.asm)中。

在看播放的流程时建议 User 结合 1,2中的描述到对应的文件中找到相关 API 函数。

1) 在 algorithm.h 和 algorithm.inc 中将 DVR1800_Used 的宏定义打开;

2) 在 main 的主循环中加入 Nand_WriteFAT_Rec()和 Nand_GetFAT_MP3()(For MP3

Play)函数;

3) 设置 Speech 算法的 Codec 值:

CodecType = C_CODEC_AUDIO1800;

SACM_Codec(CodecType);

//======================先录音==============================

4) DVR 时设置 BitRate: //只对 1800 录音的 BitRate 有效

BitRate = 32000;

SACM_DVR1800_BITRATE(BitRate);

5) 打开文件并设置录音时存储数据的回调函数指针:

FileHandle = open((LPSTR)("A:\\REC.a18"),O_CREAT|O_RDWR);

stat((LPSTR)("A:\\REC.a18"),&filestatus);

Fat_SetStartAddr(LB2LP(NFAT_DS_WriteData_Rec));

write(FileHandle,(long)Buffer<<1,4);//录音时文件的头两个 word 空出以存

放长度

6) 开始录音:

SACM_Rec(RecMonitorOff,BIT_RATE);

//=========================后放音==============================

7) 停止录音:

SACM_Stop();

close(FileHandle);

SACM_Codec(CodecType);

8) 设置读取数据的回调函数指针:

Fat_SetStartAddr(LB2LP(NFAT_DS_GetData));//MP3 为 NFAT_DS_GetData_MP3

9) 打开要播放的文件并填写文件的长度:

FileHandle = open((LPSTR)("A:\\REC.a18"),O_RDWR);

stat((LPSTR)("A:\\REC.a18"),&filestatus);

Page 20: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 20 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

Musicdata_Length=filestatus.st_size;

Musicdata_Length -= 4;

WriteWordIntoBuffer(Buffer,&Musicdata_Length,2);

write(FileHandle,(long)Buffer<<1,4);

10)Play:

lseek(FileHandle,0,SEEK_SET); //seek 到文件的开始位置

SACM_Play(Manual_Mode_Index,DAC1+DAC2,0);

4、 Debug Notes For Play or Record:

4.1 调用 Play 不出声音:

1)User 的 System.asm 是否按照 Demo 中的 RAM 定义方式定义了 SACM 必须占用

的空间,是否在相应的地址单元写上了正确的跳转指令(详见 Demo 中的 System.asm);

2)函数调用流程是否正确:是否调用了 SACM_Initial()函数,是否调用了算

法类型设置函数 SACM_Codec(),是否正确设置了算法类型(算法和资源文件是否一致),

是否调用了音量设置函数;

3)是否在 algorithm.h 和 algorithm.inc 中将相应算法的宏开关打开;

4)如果是 MS02,是否将 Tone.lib(MS02 的音色库)加到了资源文件中;

5)如果是 Play Index 的模式,是否将资源加到了 Resource.asm 中对应算法的

Table 表里面,并且将资源文件的起始地址设置正确;

4)系统时钟是否设置正常。

4.2 Play 时出现杂音:

1)如果播出来的没有资源文件的声音(为噪音),那么检查获取的 Resource

文件的数据是否正确。可以从 Decode_In_Buffer 中 Dump 出来和源文件比较;

2)如果播出来的声音断断续续,或者在播放过程中会听到杂音,这是解码不及

时的现象,检查调用 GetData 的函数是否及时,是否满足了在播放完一个缓冲 Buffer

要调用一个 GetFATData 函数的条件(如第 1部分所描述);

3)有一些情况很难查找时就在中断的 F_ISR_Service_SACM_DAC 函数中向 DAC

送数据的位置加上一个 Dump 数据的动作(详见 F_ISR_Service_SACM_DAC 函数中的如下

程序):

.ifdef dump_decode_data

push r1, r2 to [SP];

R1 = [decode_addrh];

r2 = [decode_addrl];

ds = r1;

Page 21: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 21 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

D:[R2++] = R3;

[decode_addrl] = r2;

r1 = ds;

[decode_addrh] = r1;

POP R1, R2 from [SP];

.endif

设一段全局的 Buffer,每次解码后的数据在这里存储起来,然后用 CoolEdit

播放,以确定是否是解码的问题;

4)建议外接功放用一个 IO 口的引脚来控制功放示能。

4.3 不能录音:

1)User 的 System.asm 是否按照 Demo 中的 RAM 定义方式定义了 SACM 必须占用

的空间,是否在相应的地址单元写上了正确的跳转指令(详见 Demo 中的 System.asm);

2)函数调用流程是否正确:是否调用了 SACM_Initial()函数,是否调用了算

法类型设置函数 SACM_Codec(),是否设置了录音算法的 BitRate;

3)是否在 algorithm.h 中将相应算法的宏开关打开;

4)看程序能否正常的紧中断,如果不能则检查系统时钟P_Clock_Ctrl的Bit4

是否被置位,并且P_HQADC_Ctrl的Bit0是否被置位,P_ADC_Setup是否将AutoSample

(Bit2)置位。如果正常进入中断则要检查是否正确调用了SACM_ServiceLoop函数。

4.4 录音播放有杂音:

1)如果是细微的高频尖叫声,则检查是否在录音过程中出现了低电压的情况;

2)如果是其他杂音,有可能是些文件是数据的丢失,这是要检查时否及时调用

了些文件的操作(如第一部分的描述);

3)另外就是将从DAC里录进来的数据Dump出来(详见F_ISR_Service_SACM_ADC

函数中的下列部分):

.ifdef dump_encode_data

push r1, r2 to [SP];

R1 = [encode_addrh];

r2 = [encode_addrl];

ds = r1;

R3 = D:[R2++];

[encode_addrl] = r2;

r1 = ds;

[encode_addrh] = r1;

POP R1, R2 from [SP];

.endif

在将待Encode的Data Dump出来之后用CoolEdit转化为wav档,然后用PC端工具进行

Page 22: Sound Library Users Manual withoutos - pudn.comread.pudn.com/downloads99/doc/403554/Library User... · Description Pause the current speech Header File C SACM_API.h ASM C void SACM_Pause(void);

Generalplus Sound Library User’s Manual

© Sunplus Technology Co., Ltd. PAGE 22 BR200-A-00001 V1.0.2 - OCT 14, 2005

PRELIMINARY

Encode,然后将Encode之后的文件用原程序播放,以确定是录音还是放音的问题。