开发者

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

开发者 https://www.devze.com 2023-02-02 09:05 出处:网络
Greetings, I\'m working on a low level programming project and I want to play a music with the computer speaker.

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 be开发者_JS百科st 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.


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

An example simple ringtone format is RTTTL.


anatolyg's answer is good. I just want to show how complex a task like this can be: have a look at MIDI for inspiration.

http://en.wikipedia.org/wiki/Musical_Instrument_Digital_Interface

MIDI files can be used as "virtual sheet music" for music software, storing the notes and a lot of additional information describing the nuances of playing (for example the velocity, pitch bend, modulation and so on). It was built for storing entire pieces of music with multiple instruments and polyphony.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号