Reply by FGTH September 17, 20092009-09-17
>Hi all, > >How to deal with audio files on CCS? To load data from audio file on to >some buffer array,I have tried converting it into ASCII text file, but
it
>makes the resulting file quite bulky(150MB) and its taking long time to
add
>the header at the begining. > >any ideas? > >-aamer >
CCS to Wav via Matlab and vice-versa I've developped Matlab .m files that read CCS file to Matlab, and Matlab to CCS files. Here are 4 files below. You can thus create a wav file, read it with Matlab, create a CCS file and then probe it in the CCS. Have fun. wavwr16.m === function wavwr16(wavefile,waveData,format) %WAVWRITE16 Saves Microsoft Windows 3.1 .WAV format sound files. % % WAVWR16(wavefile,y,format) saves a .WAV format file specified by "wavefile". % % The input arguments for WAVWRITE16 are as follows: % % wavefile A string containing the name of the .WAV file to create % y The sampled data to save in floating point. % Channel 0 Channel 1 % " " % ... ... % Note that these value will be truncat to 8 or 16 bits. % % format Format is a four(4) element vector of Wave file. % [1] : Coding : PCM = 1, Mu-law = 2 % [2] : Channel: Mono = 1, Stereo = 2 % [3] : Sampling rate : 8000, 11025, 22050 or 44100 ( CD quality ) % [4] : The resolution : 8 or 16 bit per sample. % % See also WAVREAD16. % Copyright (c) 1984-93 by The MathWorks, Inc. % Modify by Francois Caron, INRS-telecommunications % Version 1.0, 7-7-94 % if nargin~=3 error('WAVWRITE needs three arguments!'); end if findstr(wavefile,'.')==[] wavefile=[wavefile,'.wav']; end fid=fopen(wavefile,'wb'); if fid ~= -1 [m,n]=size(waveData); nsamples = m; if (n > format(2)) error('Can put a binaural vector into a Wave Mono sound file!'); end if ~(format(3) == 8000 | format(3) == 11025 | format(3) == 22050 | format(3) == 44100) error('Sample frequency is not WAVE standard!'); end if (format(4)+format(2) == 9) Block = 1; end if (format(4)+format(2) == 10) | (format(4)+format(2) == 17) Block = 2; end if (format(4)+format(2) == 18) Block = 4; end Riffsize=36+(Block*nsamples); % write riff chunk fwrite(fid,'RIFF','uchar'); fwrite(fid,Riffsize,'ulong'); fwrite(fid,'WAVE','uchar'); % write format sub-chunk fwrite(fid,'fmt ','uchar'); fwrite(fid,16,'ulong'); Average = (format(4)/8)*format(3)*format(2); fwrite(fid,format(1),'ushort'); % PCM or X-law format fwrite(fid,format(2),'ushort'); % x channel fwrite(fid,format(3),'ulong'); % samples per second fwrite(fid,Average,'ulong'); % average bytes per second fwrite(fid,Block,'ushort'); % block alignment fwrite(fid,format(4),'ushort'); % bits per sample % write data sub-chunck fwrite(fid,'data','uchar'); fwrite(fid,(nsamples*Block),'ulong'); if (format(4)+format(2) == 9) fwrite(fid,waveData,'uchar'); end if (format(4)+format(2) == 10) for i=1:nsamples, fwrite(fid,waveData(i,1),'uchar'); if n == 1 fwrite(fid,waveData(i,1),'uchar'); else fwrite(fid,waveData(i,2),'uchar'); end end end if (format(4)+format(2) == 17) fwrite(fid,waveData,'short'); end if (format(4)+format(2) == 18) for i=1:nsamples, fwrite(fid,waveData(i,1),'short'); if n == 1 fwrite(fid,waveData(i,1),'short'); else fwrite(fid,waveData(i,2),'short'); end end end end; if fid == -1 error('Can''t open .WAV file for input!'); end; fclose(fid); wavrd16.m ==== function [L,R,format]=wavrd16(wavefile) %WAVREAD16 Load Microsoft Windows 3.1 .WAV format sound files. % % [L,R,format]=WAVRD16(wavefile) loads a .WAV format file specified by % "wavefile", returning the sampled data in variable L and R, and the % .WAV file format information in variable "format". The format % information is returned as a 4 element vector with the following % order: % % format(1) Data format (Always PCM). % format(2) Number of channels % format(3) Sample Rate (Fs) % format(4) Bits per sample % % Note: If the Wave input file is mono, L and R will be the same. % % See also WAVWRITE16 % % Copyright (c) 1984-93 by The MathWorks, Inc. % Modified by Francois Caron, INRS-telecommunications % Version 1.1 18-8-94 if nargin~=1 error('WAVREAD takes one argument, which is the name of the .WAV file.'); end if findstr(wavefile,'.')==[] wavefile=[wavefile,'.wav']; end fid=fopen(wavefile,'rb'); if fid ~= -1 % read riff chunk header=fread(fid,4,'uchar'); header=fread(fid,1,'ulong'); header=fread(fid,4,'uchar'); % read format sub-chunk header=fread(fid,4,'uchar'); header=fread(fid,1,'ulong'); format(1)=fread(fid,1,'ushort'); % Format format(2)=fread(fid,1,'ushort'); % Channel format(3)=fread(fid,1,'ulong'); % Samples per second header=fread(fid,1,'ulong'); block=fread(fid,1,'ushort'); format(4)=fread(fid,1,'ushort'); % Bits per sample % read data sub-chunck header=fread(fid,4,'uchar'); nbyteforsamples=fread(fid,1,'ulong'); nsamples=nbyteforsamples/block; if (format(4)+format(2) == 9) L = fread(fid,nsamples,'char'); R = L; end if (format(4)+format(2) == 10) y = fread(fid,[2,nsamples],'char'); L = y(1,:)'; R = y(2,:)'; end if (format(4)+format(2) == 17) L = fread(fid,nsamples,'short'); R = L; end if (format(4)+format(2) == 18) y = fread(fid,[2,nsamples],'short'); L = y(1,:); R = y(2,:); end end if fid == -1 error('Can''t open .WAV file for input!'); end; fclose(fid); readcc.m ==== function data=ReadCC(filename) % function data=ReadCC(filename) % % Read Code Composer file % % 16 bits signed supported only % % % 13-4-2000 % Fran&ccedil;ois Caron, ing. M.Sc. fid=fopen(filename,'r'); dummy=fscanf(fid,'%x\n',5); % Skip 5 first element (header) temp=fscanf(fid,'%x\n'); % Read all the rest of data fclose(fid); for i=1:length(temp) if ( temp(i) < 32768 ) data(i,1) = temp(i); else data(i,1) = temp(i) - 65536; end end writecc.m ===== function writeCC(filename, data) % function WriteCC(filename, data) % % Write Code Composer file % % 16 bits signed supported only % % % 13-4-2000 % Fran&ccedil;ois Caron, ing. M.Sc. fid=fopen(filename,'w'); [n,m] = size(data); if (n>1) data = data'; end datalength = length(data); fprintf (fid,'1651 1 0 0 %d\n', datalength); for i=1:datalength if (data(i) >= 0) fprintf(fid,'0x%x\n', data(i)); else temp = data(i) + 65536; fprintf(fid,'0x%x\n', temp); end end
Reply by Vladimir Vassilevsky September 17, 20092009-09-17

aamer wrote:

> Hi all, > > How to deal with audio files on CCS?
Exactly in the same way like with any other files in any other C compiler. #include <stdio.h> and go ahead. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
Reply by Richard Dobson September 17, 20092009-09-17
aamer wrote:
> Hi Rune, > > its code composer studio, am trying to implement a low pass filter on > audio song. my algorithm reads the data in blocks of some size from audio > signal and loads in to buffer of same size until end of the file. > > the problem: audio song is of .mp3 format which I think cannot be given as > input file to CCS(because it has no header what CCS needs) so converted > into ASCII text format(added header manually required by CCS) which makes > the file to 150MB, which i think is not a proper solution,as a song of 40MB > is becoming 150MB, as it is usually difficult handle files of that size > when working with DSP. >
mp3 is a lossy compressed audio file format (MPEG2 layer 3 to be precise); data consists of specially defined frequency-domain frames. It has to be decoded to PCM by an mp3 decoder before it can be applied to your project. Most audio soundfile editors can decode it to WAVE for you. mp3 decoding is (a) complex and (b) can in principle only be done using a formally licensed decoder. There is the Lame decoder which is GPL. Why on earth should Code Composer Studio know anything about audio files? Use libsndfile (or some other soundfile header parser of your choice; or write your own - if necessary take the code in "wavread" in any recent version Matlab as a starting point) and in your code read the binary PCM data directly from the PCM file. Richard Dobson
Reply by Randy Yates September 17, 20092009-09-17
"aamer" <raqeebhyd@yahoo.com> writes:

> Hi all, > > How to deal with audio files on CCS? To load data from audio file on to > some buffer array,I have tried converting it into ASCII text file, but it > makes the resulting file quite bulky(150MB) and its taking long time to add > the header at the begining. > > any ideas? > > -aamer
Aamer, Use standard C binary file I/O, e.g., fopen(), fread(), etc.. When you're running code via JTAG and CCS, the C file I/O library will do the transfer over JTAG to and from your host file system transparently. It appears to your DSP code as if you had access to the host file system. -- Randy Yates % "Watching all the days go by... Digital Signal Labs % Who are you and who am I?" mailto://yates@ieee.org % 'Mission (A World Record)', http://www.digitalsignallabs.com % *A New World Record*, ELO
Reply by Randy Yates September 17, 20092009-09-17
"aamer" <raqeebhyd@yahoo.com> writes:

> Hi all, > > How to deal with audio files on CCS? To load data from audio file on to > some buffer array,I have tried converting it into ASCII text file, but it > makes the resulting file quite bulky(150MB) and its taking long time to add > the header at the begining. > > any ideas?
Aamer, Use standard C binary file I/O, e.g., fopen(), fread(), etc.. When you're running code via JTAG and CCS, the C file I/O library will do the transfer over JTAG to and from your host file system transparently. It appears to your DSP code as if you had access to the host file system. -- Randy Yates % "Midnight, on the water... Digital Signal Labs % I saw... the ocean's daughter." mailto://yates@ieee.org % 'Can't Get It Out Of My Head' http://www.digitalsignallabs.com % *El Dorado*, Electric Light Orchestra
Reply by aamer September 17, 20092009-09-17
Hi Rune,

I found its difficult(time taking) to deal with data files converted from
audio files.

and CCS is code composer studio, what kind of files does ccs take as
input? is it just .dat........or can I work with .mp3 also directly without
converting in to .dat

same is the question when we try to write on to some file.

-aamer


>On 17 Sep, 09:10, "aamer" <raqeeb...@yahoo.com> wrote: >> Hi all, >> >> How to deal with audio files on CCS? To load data from audio file on
to
>> some buffer array,I have tried converting it into ASCII text file, but
it
>> makes the resulting file quite bulky(150MB) and its taking long time to
add
>> the header at the begining. > >What is CCS? > >As for text-format files, expect 30-60 seconds per 100 MBytes >for read/write operations. It takes ridiculous amounts of time >to convert numbers back and forth between text and binary >formats. > >Adding headers to the beginning of an already existing file >takes time. The algorithm goes something like > >- Make a new, empty file >- Write the header to this new file >- Copy the contents from the original file to the new file >- Delete the original file >- Rename the new file with the original file name > >If you can, deduce the header info before you start writing >the file at all, and insert the header first time around. > >Rune >
Reply by aamer September 17, 20092009-09-17
Hi Rune,

its code composer studio, am trying to implement a low pass filter on
audio song. my algorithm reads the data in blocks of some size from audio
signal and loads in to buffer of same size until end of the file.

the problem: audio song is of .mp3 format which I think cannot be given as
input file to CCS(because it has no header what CCS needs) so converted
into ASCII text format(added header manually required by CCS) which makes
the file to 150MB, which i think is not a proper solution,as a song of 40MB
is becoming 150MB, as it is usually difficult handle files of that size
when working with DSP.

-aamer














>On 17 Sep, 09:10, "aamer" <raqeeb...@yahoo.com> wrote: >> Hi all, >> >> How to deal with audio files on CCS? To load data from audio file on
to
>> some buffer array,I have tried converting it into ASCII text file, but
it
>> makes the resulting file quite bulky(150MB) and its taking long time to
add
>> the header at the begining. > >What is CCS? > >As for text-format files, expect 30-60 seconds per 100 MBytes >for read/write operations. It takes ridiculous amounts of time >to convert numbers back and forth between text and binary >formats. > >Adding headers to the beginning of an already existing file >takes time. The algorithm goes something like > >- Make a new, empty file >- Write the header to this new file >- Copy the contents from the original file to the new file >- Delete the original file >- Rename the new file with the original file name > >If you can, deduce the header info before you start writing >the file at all, and insert the header first time around. > >Rune >
Reply by Rune Allnor September 17, 20092009-09-17
On 17 Sep, 09:10, "aamer" <raqeeb...@yahoo.com> wrote:
> Hi all, > > How to deal with audio files on CCS? To load data from audio file on to > some buffer array,I have tried converting it into ASCII text file, but it > makes the resulting file quite bulky(150MB) and its taking long time to add > the header at the begining.
What is CCS? As for text-format files, expect 30-60 seconds per 100 MBytes for read/write operations. It takes ridiculous amounts of time to convert numbers back and forth between text and binary formats. Adding headers to the beginning of an already existing file takes time. The algorithm goes something like - Make a new, empty file - Write the header to this new file - Copy the contents from the original file to the new file - Delete the original file - Rename the new file with the original file name If you can, deduce the header info before you start writing the file at all, and insert the header first time around. Rune
Reply by aamer September 17, 20092009-09-17
Hi all,

How to deal with audio files on CCS? To load data from audio file on to
some buffer array,I have tried converting it into ASCII text file, but it
makes the resulting file quite bulky(150MB) and its taking long time to add
the header at the begining.

any ideas?

-aamer