4.5. IMelodySpeakerCommandBuilder

added in version 1.7.0

This interface provides the function which creates melody speaker control commands.

This interface is only for models which support a melody speaker and for FVP10.For the supporting models, refer to Supported Peripherals .

  • Property

    Name

    Contents

    Commands

    Generated commands.

  • Method

    Name

    Contents

    AppendSound

    The command for playback of a sound registered in the melody speaker is generated and added to the command buffer.

    AppendSoundData

    A command for playback of the sound data specified by the argument is generated and added to the command buffer.

4.5.1. MelodySpeakerSoundStorageArea

added in version 1.7.0

Constant that specifies the sound storage area.

  • Declaration

    public enum MelodySpeakerSoundStorageArea {
        Area1,
        Area2
    }
    

The sound storage areas which correspond to the constants are the following.

MelodySpeakerModel Constants Sound storage area
MCS10
Area1
Area2
Sound storage area1
Sound storage area2
FVP10
Area1
Area2
Default area
User area

4.5.2. Commands

added in version 1.7.0

Gets the command buffer (generated command).

  • Declaration

    byte[] Commands { get; }
    
  • Parameter

    None

  • Return value

    Contents Type
    Cmmand buffer (generated command) byte[]

4.5.3. AppendSound

added in version 1.7.0

The command for playback of a sound registered in the melody speaker is generated and added to the command buffer.

  • Declaration

    void AppendSound(SoundSetting setting);
    
  • Parameter

    Name Contents Type
    setting Settings information for the playback sound (sound storage area, sound number, etc.) SoundSetting

    The parameters which can be set in the setting argument are the following.

    MelodySpeakerModel

    Property

    Contents

    Parameters that can be set

    Default (operation when nothing is specified)

    MCS10

    SoundStorageArea

    Sound storage area

    Area1

    Use the MCS10 unit DIP switch settings.

    Area2

    SoundNumber

    Sound number

    0 - 7

    Use the MCS10 unit DIP switch settings.

    Volume

    Volume

    0 – 15

    Use the MCS10 unit DIP switch settings.

    SoundSetting.VolumeOff

    SoundSetting.VolumeMax

    SoundSetting.VolumeMin

    FVP10

    SoundStorageArea

    Sound storage area

    Area1

    Area1

    Area2

    SoundNumber

    Sound number

    1 - 255 1

    Count

    Count

    1 - 65535 1

    Delay

    Delay time (1 sec units)

    0 - 65535 0

    Interval

    Interval time (1 sec units)

    0 - 65535 0

    Sound played according to the combination of parameters specified for the SoundStorageArea property and SoundNumber property are as follows.

    MelodySpeakerModel

    SoundStorageArea

    SoundNumber

    Sound

    MCS10

    Area1

    0

    Sound1

    1

    Sound2

    2

    Sound3

    3

    Sound4

    4

    Sound5

    5

    Sound6

    6

    Sound7

    7

    Sound8

    Area2

    0

    Sound9

    1

    Sound10

    2

    Sound11

    3

    Sound12

    4

    Sound13

    5

    Sound14

    6

    Sound15

    7

    Sound16

    FVP10

    Area1

    1 - 255

    Sound stored in the specified sound number of the default area

    Area2

    1 - 255

    Sound stored in the specified sound number of the user area

  • Return value

    None

  • Exception

    Class Contents
    ArgumentException
    One of the following
    1. The property that can not be set on the specified model is set
    2. Only one of the SoundStorageArea property and the SoundNumber property is set
    ArgumentOutOfRangeException Parameter is out of range
  • Examples

    public static byte[] CreatePlayingRegisteredSoundData(MelodySpeakerModel model, bool specifySound, MelodySpeakerSoundStorageArea soundStorageArea, int soundNumber, bool specifyVolume, int volume)
    {
        IMelodySpeakerCommandBuilder builder = StarIoExt.CreateMelodySpeakerCommandBuilder(model); SoundSetting setting = new SoundSetting();
    
        if (specifySound)
        {
            setting.SoundStorageArea = soundStorageArea;
            setting.SoundNumber = soundNumber;
        }
    
        if (specifyVolume)
        {
            setting.Volume = volume;
        }
    
        builder.AppendSound(setting);
    
        return builder.Commands;
    }
    

    Refer to MelodySpeakerFunction.cs

4.5.4. AppendSoundData

added in version 1.7.0

A command for playback of the sound data specified by the argument is generated and added to the command buffer.

Warning

FVP10 is not supported.

  • Declaration

    void AppendSoundData(byte[] data, SoundSetting setting);
    
  • Parameter

    Name Contents Type
    data Sound data byte[]
    setting Settings information for the playback sound (sound storage area, sound number, etc.) SoundSetting

    For the supported sound formats, refer to the table of supported sound formats.

    Name Value
    Sound file format WAV
    WAV file format Linear PCM
    Sampling rate 12800Hz
    Bit depth 16 bits or 8 bits
    Channel Monaural
    Playback time
    Max. 5 sec when bitdepth is 16
    Max. 10 sec when bitdepth is 8

    1. It is possible to convert a sound file format to a format in the table of supported sound formats by using the Start Sound Converter application that was provided with this package. For details, refer to “FileFormatList_en.htm” in “Others/StarSoundConverter/(Windows or Mac)/Documents” folder.

    The parameters which can be set in the setting argument are the following.

    Property Contents Parameters that can be set Default (operation when nothing is specified)
    Volume Volume
    0 – 15
    SoundSetting.VolumeOff
    SoundSetting.VolumeMax
    SoundSetting.VolumeMin
    Use the MCS10 unit DIP switch settings.
  • Return value

    None

  • Exception

    Class Contents
    FormatException Data other than a supported sound format is input
    ArgumentException The property that can not be set on the specified model is set
    ArgumentOutOfRangeException Parameter is out of range
    InvalidOperationException FVP10 is specified.
  • Examples

    public static byte[] CreatePlayingSoundData(MelodySpeakerModel model, StorageFile file, bool specifyVolume, int volume)
    {
        IAsyncOperation<IBuffer> readOperation = FileIO.ReadBufferAsync(file);
    
        byte[] data = readOperation.AsTask().Result.ToArray();
    
        IMelodySpeakerCommandBuilder builder = StarIoExt.CreateMelodySpeakerCommandBuilder(model);
    
        SoundSetting setting = new SoundSetting();
    
        if (specifyVolume)
        {
            setting.Volume = volume;
        }
    
        builder.AppendSoundData(data, setting);
    
        return builder.Commands;
    }
    

    Refer to MelodySpeakerFunction.cs