CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

how i made sound from music files

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
a
Guest







how i made sound from music files
PostPosted: Wed Feb 18, 2004 3:45 am     Reply with quote

how i made sound from music files(examples .wav, .mp3 or other files) or create music in Pic16f877
i used to read sourcecode(ex_tones.c)
but
// NOTE FREQUENCY
// Octave0 Octave1 Octave2 Octave3
const long C_NOTE[4] ={ 262, 523, 1047, 2093};
const long Db_NOTE[4] ={ 277, 554, 1109, 2217};
const long D_NOTE[4] ={ 294, 587, 1175, 2349};
const long Eb_NOTE[4] ={ 311, 622, 1245, 2489};
const long E_NOTE[4] ={ 330, 659, 1329, 2637};
const long F_NOTE[4] ={ 349, 698, 1397, 2794};
const long Gb_NOTE[4] ={ 370, 740, 1480, 2960};
const long G_NOTE[4] ={ 392, 784, 1568, 3136};
const long Ab_NOTE[4] ={ 415, 831, 1661, 3322};
const long A_NOTE[4] ={ 440, 880, 1760, 3520};
const long Bb_NOTE[4] ={ 466, 923, 1865, 3729};
const long B_NOTE[4] ={ 494, 988, 1976, 3951};
....
....
....
void generate_tone(long frequency, long duration)

but can i know duration time from music files (examples .wav, .mp3 or other files)





Please help me.
Guest








PostPosted: Wed Feb 18, 2004 9:32 am     Reply with quote

There is a DOS- Software which inputs wav- files and creates a retlw-table for a sort of pwm output in a pic.
You can found it at www.romanblack.com .
Hope this helps.

Thomas
a
Guest







PostPosted: Wed Feb 18, 2004 10:45 pm     Reply with quote

if i have note of music. How i know duration which i should fill in duration variable. thank you for all help. i will download software that u ask me.
Spiffy



Joined: 21 Jan 2004
Posts: 12

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Fri Feb 20, 2004 8:37 am     Reply with quote

What is this program from what I can understand it can generate a frequency that sounds like a music note and you reproduce a song???
or is it the real song thats reproduced??
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri Feb 20, 2004 9:13 am     Reply with quote

Kind of like sheet music.
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

very simple sound
PostPosted: Sat Nov 25, 2006 2:26 pm     Reply with quote

I want to generate a very simple sound like "hey", "stop", "jump" or anything similar.

it seems logical to use roman black's nice software (Thanks Roman!).

The software generates asm code of retlw instructions. How can i use that asm instructions in my CCS C program?

i wonder whether it is possible to generate that very simple syllable with a simple controller like the 16F628. I wonder did anyone tried that before?
_________________
www.endtas.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 26, 2006 1:52 pm     Reply with quote

You can type the data into an array. For example, here's the first
16 bytes of data generated by Roman's program for his Dick09.wav file.
Code:

     retlw b'00010010'   ; 12
     retlw b'01011110'   ; 5e
     retlw b'10101010'   ; aa
     retlw b'10101010'   ; aa
     retlw b'11001010'   ; ca
     retlw b'10101010'   ; aa
     retlw b'10101010'   ; aa
     retlw b'10110010'   ; b2
     ;------------------------- 
     retlw b'10101010'   ; aa
     retlw b'10100101'   ; a5
     retlw b'01100110'   ; 66
     retlw b'11001101'   ; cd
     retlw b'00101010'   ; 2a
     retlw b'11001100'   ; cc
     retlw b'11001100'   ; cc
     retlw b'10011010'   ; 9a


In the program below, those bytes have used to initialize the
'sound_data' array. This array is declared as a 'const' array,
which means the data will be placed in ROM. For the 16F series,
the size limit of a const array is 256 bytes. So even though I've
shown only 16 bytes, you can add up to 240 more bytes to it.
You can also add more arrays (with different names).
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

const char sound_data[] =
{
0x12,0x5e,0xaa,0xaa,0xca,0xaa,0xaa,0xb2,
0xaa,0xa5,0x66,0xcd,0x2a,0xcc,0xcc,0x9a
};

//============================
void main()
{
int8 i;
int8 c;

c = sound_data[i];

while(1);
}



When the program above is compiled, the array data will be stored
in RETLW statements. You can see it in the MPLAB Disassembly Listing
window:
Code:

  0004    100A     BCF 0xa, 0
  0005    108A     BCF 0xa, 0x1
  0006    110A     BCF 0xa, 0x2
  0007    0782     ADDWF 0x2, F
  0008    3412     RETLW 0x12
  0009    345E     RETLW 0x5e
  000A    34AA     RETLW 0xaa
  000B    34AA     RETLW 0xaa
  000C    34CA     RETLW 0xca
  000D    34AA     RETLW 0xaa
  000E    34AA     RETLW 0xaa
  000F    34B2     RETLW 0xb2
  0010    34AA     RETLW 0xaa
  0011    34A5     RETLW 0xa5
  0012    3466     RETLW 0x66
  0013    34CD     RETLW 0xcd
  0014    342A     RETLW 0x2a
  0015    34CC     RETLW 0xcc
  0016    34CC     RETLW 0xcc
  0017    349A     RETLW 0x9a
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

thanks
PostPosted: Mon Nov 27, 2006 2:12 am     Reply with quote

Then it is only a matter of typing the codes generated by rowans's program. I wonder what is the max duration of sound which can be produced with the data a pic16F628's 2kword program memory can hold.
_________________
www.endtas.com
JED



Joined: 13 Jul 2006
Posts: 8

View user's profile Send private message

PostPosted: Mon Nov 27, 2006 7:31 pm     Reply with quote

Hi, over the past weekend I was playing with a similar project. I used winhex a program referred to on other post on this form(see link), to manipulate a .wav file. Using windows sound recorder i created an 8 bit 8 KHz mono PMC .wav file. This was then imported into win hex to strip off the header and preserve only the raw sound data. winhex has a utility to export the data to a c code formatted array. To play the .wav on the pic a entry of the array is fed into the duty cycle of the PIC’s PWM module every 125uS. Using only a 220uF cap to ac couple an 8 ohm speaker made for a very crude talking PIC. I’m sure a low pass filter is necessary to get rid of the high frequencies present in the square wave PWM output. This method is simple but a huge memory hog. Using an 18f2455 I could only get a few seconds of sound (@8000 sample/second).
[/url]http://www.ccsinfo.com/forum/viewtopic.php?t=25702&highlight=winhex[/url][/url]
hobiadami



Joined: 17 Oct 2006
Posts: 35
Location: City of Concrete

View user's profile Send private message Visit poster's website ICQ Number

sample code?
PostPosted: Tue Aug 14, 2007 12:36 pm     Reply with quote

Hi Jed,

can you post some working code here for me to test in proteus?

thanks.
_________________
www.endtas.com
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group