Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a music into a array of frequencies and durations of its notes

Greetings,

I'm working on a low level programming project and I want to play a music with the computer speaker.

I'm already capable of using the speaker (with timer2) and a song is represented in the following way:

note_t *music;

where note_t represents a note and it's compound by:

typedef struct {
  int freq; /* note frequency */
  int dur;  /* note duration in miliseconds */
} note_t;

Now, what would be the best way to get the frequencies and durations of the notes from a music file?

Thanks in advance!

EDIT

To clarify some doubts, what I want to know is the best format to get the necessary information to create a song with the structure above indicated.

like image 904
Renato Rodrigues Avatar asked Dec 17 '25 04:12

Renato Rodrigues


1 Answers

Depending on your exact purpose, you can use one of the ringtone formats or invent your own.

An example simple ringtone format is RTTTL.

like image 167
anatolyg Avatar answered Dec 19 '25 23:12

anatolyg