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


Committer:
Osamu Nakamura
Date:
Mon Apr 24 19:05:48 2017 +0900
Revision:
3:9e8c5b0d9fba
Parent:
0:0ff243f7fb2d
Introduce mbed OS 5 instead of mbed OS 2 (Classic)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MasaoHamanaka 0:0ff243f7fb2d 1 /******************************************************************************
MasaoHamanaka 0:0ff243f7fb2d 2 * DISCLAIMER
MasaoHamanaka 0:0ff243f7fb2d 3 * This software is supplied by Renesas Electronics Corporation and is only
MasaoHamanaka 0:0ff243f7fb2d 4 * intended for use with Renesas products. No other uses are authorized. This
MasaoHamanaka 0:0ff243f7fb2d 5 * software is owned by Renesas Electronics Corporation and is protected under
MasaoHamanaka 0:0ff243f7fb2d 6 * all applicable laws, including copyright laws.
MasaoHamanaka 0:0ff243f7fb2d 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
MasaoHamanaka 0:0ff243f7fb2d 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
MasaoHamanaka 0:0ff243f7fb2d 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
MasaoHamanaka 0:0ff243f7fb2d 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
MasaoHamanaka 0:0ff243f7fb2d 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
MasaoHamanaka 0:0ff243f7fb2d 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
MasaoHamanaka 0:0ff243f7fb2d 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
MasaoHamanaka 0:0ff243f7fb2d 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
MasaoHamanaka 0:0ff243f7fb2d 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
MasaoHamanaka 0:0ff243f7fb2d 16 * Renesas reserves the right, without notice, to make changes to this software
MasaoHamanaka 0:0ff243f7fb2d 17 * and to discontinue the availability of this software. By using this software,
MasaoHamanaka 0:0ff243f7fb2d 18 * you agree to the additional terms and conditions found by accessing the
MasaoHamanaka 0:0ff243f7fb2d 19 * following link:
MasaoHamanaka 0:0ff243f7fb2d 20 * http://www.renesas.com/disclaimer
MasaoHamanaka 0:0ff243f7fb2d 21 * Copyright (C) 2012 - 2015 Renesas Electronics Corporation. All rights reserved.
MasaoHamanaka 0:0ff243f7fb2d 22 ******************************************************************************/
MasaoHamanaka 0:0ff243f7fb2d 23
MasaoHamanaka 0:0ff243f7fb2d 24 #ifndef _SCORE_H
MasaoHamanaka 0:0ff243f7fb2d 25 #define _SCORE_H
MasaoHamanaka 0:0ff243f7fb2d 26
MasaoHamanaka 0:0ff243f7fb2d 27
MasaoHamanaka 0:0ff243f7fb2d 28 /* De Camptown Races */
MasaoHamanaka 0:0ff243f7fb2d 29 #define SCORE_DeCamptownRaces \
MasaoHamanaka 0:0ff243f7fb2d 30 "120" \
MasaoHamanaka 0:0ff243f7fb2d 31 "+a8+a8+a8f#8+a8+b8+a8f#8r8" \
MasaoHamanaka 0:0ff243f7fb2d 32 "f#8e3f#8e4+a8+a8+a8f#8+a8+b8+a8f#8r8e4f#8e8d4r8" \
MasaoHamanaka 0:0ff243f7fb2d 33 "+a8+a8+a8f#8+a16+a16+b8+a8f#8r8" \
MasaoHamanaka 0:0ff243f7fb2d 34 "f#8e3f#8e4+a8+a8+a8f#8+a16+a16+b16+b16+a16+a16f#8r8e4f#8e8d3r8" \
MasaoHamanaka 0:0ff243f7fb2d 35 "d6d16f#8+a8+d3r8+b6+b16+d8+b8+a8r8" \
MasaoHamanaka 0:0ff243f7fb2d 36 "f#16g16+a8+a8f#16f#16+a16+a16+b8+a8f#4 e8f#16g16f#8e8d4r8"
MasaoHamanaka 0:0ff243f7fb2d 37
MasaoHamanaka 0:0ff243f7fb2d 38
MasaoHamanaka 0:0ff243f7fb2d 39 /* Red River Valley */
MasaoHamanaka 0:0ff243f7fb2d 40 #define SCORE_RedRiverValley \
MasaoHamanaka 0:0ff243f7fb2d 41 "68" \
MasaoHamanaka 0:0ff243f7fb2d 42 "d8g8+b4+b8+b8+b4+a8+b8+a8g4.r4" \
MasaoHamanaka 0:0ff243f7fb2d 43 "d8g8+b4g8+b8+d4+c8+b8+a2r4" \
MasaoHamanaka 0:0ff243f7fb2d 44 "+d8+c8+b4+b8+a8g4+a8+b8+d8+c4.r4" \
MasaoHamanaka 0:0ff243f7fb2d 45 "e8d#8d4f#8g8+a4+b8+a8g2." \
MasaoHamanaka 0:0ff243f7fb2d 46 "r8"
MasaoHamanaka 0:0ff243f7fb2d 47
MasaoHamanaka 0:0ff243f7fb2d 48 /* Jingle Bells */
MasaoHamanaka 0:0ff243f7fb2d 49 #define SCORE_JingleBells\
MasaoHamanaka 0:0ff243f7fb2d 50 "110" \
MasaoHamanaka 0:0ff243f7fb2d 51 "e8e8e4@1 e8e8e4@1 e8g8c8.d16@1 e2@1" \
MasaoHamanaka 0:0ff243f7fb2d 52 "f8f8f8.f16@1 f8e8e8e16e16@1" "e8d8d8c8@1 d8g4.@1" \
MasaoHamanaka 0:0ff243f7fb2d 53 "e8e8e4@1 e8e8e4@1 e8g8c8.d16@1 e2@1" \
MasaoHamanaka 0:0ff243f7fb2d 54 "f8f8f8.f16@1 f8e8e8e16e16@1" "g8g8f8d8@1 c4.r8@1"
MasaoHamanaka 0:0ff243f7fb2d 55
MasaoHamanaka 0:0ff243f7fb2d 56 /* We Wish You a Merry Christmas */
MasaoHamanaka 0:0ff243f7fb2d 57 #define SCORE_WeWishYouAMerryChristmas \
MasaoHamanaka 0:0ff243f7fb2d 58 "144" \
MasaoHamanaka 0:0ff243f7fb2d 59 "d4 g4g8+a8g8f#8 e4e4e4 +a4+a8+b8+a8g8 f#4d4d4" \
MasaoHamanaka 0:0ff243f7fb2d 60 "+b4+b8+c8+b8+a8 g4e4d8d8 e4+a4f#4 g4r4" \
MasaoHamanaka 0:0ff243f7fb2d 61 "d4" \
MasaoHamanaka 0:0ff243f7fb2d 62 "g4g4g4 f#2f#4 g4f#4e4 d4r4+a4" \
MasaoHamanaka 0:0ff243f7fb2d 63 "+b4+a4g4 +d4d4d8d8 e4+a4f#4g2r4"
MasaoHamanaka 0:0ff243f7fb2d 64
MasaoHamanaka 0:0ff243f7fb2d 65 /* define score for each channel */
MasaoHamanaka 0:0ff243f7fb2d 66 #define SCORE1 SCORE_DeCamptownRaces
MasaoHamanaka 0:0ff243f7fb2d 67 #define SCORE3 SCORE_RedRiverValley
MasaoHamanaka 0:0ff243f7fb2d 68
MasaoHamanaka 0:0ff243f7fb2d 69 #ifndef SCORE0
MasaoHamanaka 0:0ff243f7fb2d 70 #define SCORE0 NULL
MasaoHamanaka 0:0ff243f7fb2d 71 #endif
MasaoHamanaka 0:0ff243f7fb2d 72
MasaoHamanaka 0:0ff243f7fb2d 73 #ifndef SCORE1
MasaoHamanaka 0:0ff243f7fb2d 74 #define SCORE1 NULL
MasaoHamanaka 0:0ff243f7fb2d 75 #endif
MasaoHamanaka 0:0ff243f7fb2d 76
MasaoHamanaka 0:0ff243f7fb2d 77 #ifndef SCORE2
MasaoHamanaka 0:0ff243f7fb2d 78 #define SCORE2 NULL
MasaoHamanaka 0:0ff243f7fb2d 79 #endif
MasaoHamanaka 0:0ff243f7fb2d 80
MasaoHamanaka 0:0ff243f7fb2d 81 #ifndef SCORE3
MasaoHamanaka 0:0ff243f7fb2d 82 #define SCORE3 NULL
MasaoHamanaka 0:0ff243f7fb2d 83 #endif
MasaoHamanaka 0:0ff243f7fb2d 84
MasaoHamanaka 0:0ff243f7fb2d 85 #endif /*_SCORE_H*/
MasaoHamanaka 0:0ff243f7fb2d 86 /* End of File */