4.4. IMelodySpeakerCommandBuilder

added in version 1.10.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 .

  • Constant

    Name

    Contents

    SoundStorageArea

    Constant that specifies the sound storage area

  • 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.

    getCommands

    Gets the command buffer (generated command).

4.4.1. SoundStorageArea

added in version 1.10.0

Constant that specifies the sound storage area.

  • Declaration

    enum SoundStorageArea {
        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.4.2. appendSound

added in version 1.10.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

    Method

    Contents

    Parameters that can be set

    Default (operation when nothing is specified)

    MCS10

    setSoundStorageArea

    Sound storage area

    Area1

    Use the MCS10 unit DIP switch settings.

    Area2

    setSoundNumber

    Sound number

    0 - 7

    Use the MCS10 unit DIP switch settings.

    setVolume

    Volume

    0 – 15

    Use the MCS10 unit DIP switch settings.

    SoundSetting.VOLUME_OFF

    SoundSetting.VOLUME_MAX

    SoundSetting.VOLUME_MIN

    FVP10

    setSoundStorageArea

    Sound storage area

    Area1

    Area1

    Area2

    setSoundNumber

    Sound number

    1 - 255 1

    setCount

    Count

    1 - 65535 1

    setDelay

    Delay time (1 sec units)

    0 - 65535 0

    setInterval

    Interval time (1 sec units)

    0 - 65535 0

    Sound played according to the combination of parameters specified for the setSoundStorageArea method and setSoundNumber method are as follows.

    MelodySpeakerModel

    setSoundStorageArea

    setSoundNumber

    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
    IllegalArgumentException
    One of the following
    1. The property that can not be set on the specified model is set
    2. Only one of the setSoundStorageArea method and the setSoundNumber method is called
    3. Parameter is out of range
  • Examples

    public static byte[] createPlayingRegisteredSound(MelodySpeakerModel model, SoundStorageArea soundStorageArea, boolean specifySound, int soundNumber, boolean specifyVolume, int volume) {
        IMelodySpeakerCommandBuilder builder = StarIoExt.createMelodySpeakerCommandBuilder(model);
    
        SoundSetting setting = new SoundSetting();
    
        if (specifySound) {
            setting.setSoundStorageArea(soundStorageArea);
            setting.setSoundNumber(soundNumber);
        }
    
        if (specifyVolume) {
            setting.setVolume(volume);
        }
    
        builder.appendSound(setting);
    
        return builder.getCommands();
    }
    

    Refer to MelodySpeakerFunctions.java.

4.4.3. appendSoundData

added in version 1.10.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.

    Method Contents Parameters that can be set Default (operation when nothing is specified)
    setVolume Volume
    0 – 15
    SoundSetting.VOLUME_OFF
    SoundSetting.VOLUME_MAX
    SoundSetting.VOLUME_MIN
    Use the MCS10 unit DIP switch settings.
  • Return value

    None

  • Exception

    Class Contents
    IllegalArgumentException
    One of the following
    1. Data other than a supported sound format is input
    2. The property that can not be set on the specified model is set
    3. Parameter is out of range
    UnsupportedOperationException FVP10 is specified
  • Examples

    public static byte[] createPlayingReceivedData(MelodySpeakerModel model, Uri uri, boolean specifyVolume, int volume, Context context) {
        InputStream inputStream = null;
        byte[] soundData;
    
        try {
            inputStream = context.getContentResolver().openInputStream(uri);
    
            byte[] buffer = new byte[1024];
    
            int bytesRead;
    
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    
            while ((bytesRead = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, bytesRead);
            }
    
            soundData = outputStream.toByteArray();
            inputStream.close();
        }
        ...
    
        IMelodySpeakerCommandBuilder builder = StarIoExt.createMelodySpeakerCommandBuilder(model);
    
        SoundSetting setting = new SoundSetting();
    
        if (specifyVolume) {
            setting.setVolume(volume);
        }
    
        builder.appendSoundData(soundData, setting);
    
        return builder.getCommands();
    }
    

    Refer to MelodySpeakerFunctions.java.

4.4.4. getCommands

added in version 1.10.0

Gets the command buffer (generated command).

  • Declaration

    byte[] getCommands();
    
  • Parameter

    None

  • Return value

    Contents Type
    Cmmand buffer (generated command) byte[]