Sound Generator Sample

Dependencies:   Sound_Generator

Fork of Sound_Generator_Sample by GR-PEACH_producer_meeting

Information

Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.

Connection

The Connection is shown below.
Connect GR-PEACH and Amplifier with speaker as shown in figure.

/media/uploads/1050186/template_platform_images.png

Music playback function

What is this ?

This is a program to play music by using sound generator in RZ/A1H.

Music Data

Music data is described in score.h.
Music data is described by string of C language.
Range of tone is 4 octaves.
The format of music data is shown below:

  1. Tempo
  2. Tone data
  3. ‘\0’

"Tempo" specifies number of quarter notes per minute.
"Tone data" is composed of the following characters.

  • Zero or more space characters.
  • “-”,“+”, or “*” specifies octave. This is optional.
  • "A" to "G" specifies key notation, or "R" specifies rest.
  • "#" specifies sharp. This is optional.
  • 1-digit or two-digit number that indicates the note value.
  • "." specifies doted-note. This is optional.
  • "." specifies tie. This is optional.
  • "@" specifies synchronized marker. This is optional.
  • 1-digit or two-digit number following synchronized marker, indicates the marker IDs.

For example, the score is expressed as follows.
/media/uploads/RyoheiHagimoto/sample_score1.png

120c4d4e4f4g4+a4b4r4


The default setting of serial communication (baud rate etc.) in mbed is shown the following link.
Please refer to the link and change the settings of your PC terminal software.
The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication


接続

接続方法を以下に示します。
GR-PEACHとアンプ付きスピーカーを図のように接続してください。 /media/uploads/1050186/template_platform_images.png

楽曲再生機能

概要

RZ/A1Hに搭載されているサウンドジェネレータを使用して、簡単な音楽を再生するためのプログラムです。

楽曲データ

score.hには楽曲データが記載されています。
楽曲データは、C言語の文字列で記述します。
現在は、大よそ4オクターブが指定できます。
楽曲データのフォーマットは次のとおりです。

  1. テンポ
  2. 音符の羅列
  3. ‘\0’ (C言語の文字列の終端文字; 自動で入るものでOKです。)

テンポは、1分あたりの四分音符の数です。

音符は、次の文字で構成されます。

  • 0個以上のスペース
  • オクターブを表す“-”、“+”、“*”、又は省略
  • 音階を表す“A”~“G”、又は休符を表す“R”
  • シャープを表す“#”、又は省略
  • 長さを表す1~2桁の数字
  • 付点音符を表す“.”、又は省略
  • タイを表す“_”、又は省略
  • 同期マーカ“@”、又は省略
  • 同期マーカがある場合、同期マーカIDとなる1~2桁の数字

例えば、以下のような楽譜の場合、
/media/uploads/RyoheiHagimoto/sample_score1.png
次のように記述します。

120c4d4e4f4g4+a4b4r4


mbedのシリアル通信(ボーレート等)のデフォルト設定は以下のリンクに示しています。
リンクを参考に、お使いのPCターミナルソフトの設定を変更して下さい。
mbedでのボーレートのデフォルト値は9600で、このサンプルではボーレート9600を使います。
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication