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


score.h

Committer:
Osamu Nakamura
Date:
24 months ago
Revision:
3:9e8c5b0d9fba
Parent:
0:0ff243f7fb2d

File content as of revision 3:9e8c5b0d9fba:

/******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only
* intended for use with Renesas products. No other uses are authorized. This
* software is owned by Renesas Electronics Corporation and is protected under
* all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software
* and to discontinue the availability of this software. By using this software,
* you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
* Copyright (C) 2012 - 2015 Renesas Electronics Corporation. All rights reserved.
******************************************************************************/

#ifndef    _SCORE_H
#define    _SCORE_H


/* De Camptown Races */
#define    SCORE_DeCamptownRaces                                        \
    "120"                                                               \
    "+a8+a8+a8f#8+a8+b8+a8f#8r8"                                        \
    "f#8e3f#8e4+a8+a8+a8f#8+a8+b8+a8f#8r8e4f#8e8d4r8"                   \
    "+a8+a8+a8f#8+a16+a16+b8+a8f#8r8"                                   \
    "f#8e3f#8e4+a8+a8+a8f#8+a16+a16+b16+b16+a16+a16f#8r8e4f#8e8d3r8"    \
    "d6d16f#8+a8+d3r8+b6+b16+d8+b8+a8r8"                                \
    "f#16g16+a8+a8f#16f#16+a16+a16+b8+a8f#4 e8f#16g16f#8e8d4r8"


/* Red River Valley */
#define    SCORE_RedRiverValley             \
    "68"                                    \
    "d8g8+b4+b8+b8+b4+a8+b8+a8g4.r4"        \
    "d8g8+b4g8+b8+d4+c8+b8+a2r4"            \
    "+d8+c8+b4+b8+a8g4+a8+b8+d8+c4.r4"      \
    "e8d#8d4f#8g8+a4+b8+a8g2."              \
    "r8"

/* Jingle Bells */
#define    SCORE_JingleBells\
    "110"                                                \
    "e8e8e4@1 e8e8e4@1 e8g8c8.d16@1 e2@1"                \
    "f8f8f8.f16@1 f8e8e8e16e16@1" "e8d8d8c8@1 d8g4.@1"   \
    "e8e8e4@1 e8e8e4@1 e8g8c8.d16@1 e2@1"                \
    "f8f8f8.f16@1 f8e8e8e16e16@1" "g8g8f8d8@1 c4.r8@1"

/* We Wish You a Merry Christmas */
#define    SCORE_WeWishYouAMerryChristmas                \
    "144"                                                \
    "d4 g4g8+a8g8f#8 e4e4e4 +a4+a8+b8+a8g8 f#4d4d4"      \
    "+b4+b8+c8+b8+a8 g4e4d8d8 e4+a4f#4 g4r4"             \
    "d4"                                                 \
    "g4g4g4 f#2f#4 g4f#4e4 d4r4+a4"                      \
    "+b4+a4g4 +d4d4d8d8 e4+a4f#4g2r4"

/* define score for each channel */
#define     SCORE1      SCORE_DeCamptownRaces
#define     SCORE3      SCORE_RedRiverValley

#ifndef     SCORE0
#define     SCORE0      NULL
#endif

#ifndef     SCORE1
#define     SCORE1      NULL
#endif

#ifndef     SCORE2
#define     SCORE2      NULL
#endif

#ifndef     SCORE3
#define     SCORE3      NULL
#endif

#endif    /*_SCORE_H*/
/* End of File */