Speaker usage for watchfaces

Hello,

It would be really great to be able to use the speaker API for watchfaces. It seems usage is limited for apps only as of the latest SDK.

Why is that? And what are your thoughts on this?

I’m thinking about the classic 4096 Hz Casio hourly chime. I want to recreate that for a watchface.

1 Like

Did you try? Works here (in C)

Sadly the playback start isn’t sharp though

1 Like

I did try, also in C, but couldn’t get it to produce any sound. This is on the P2D.

What do you mean by it not being “sharp”?

1 Like

I have a PT2 but it works on the emulator for the P2D…

There’s a fade-in to sounds, kinda ruins this kind of thing. Maybe can be worked around with a sample that has some blank at the start, didn’t try that but both speaker_play_tone() and speaker_play_notes() do it

1 Like

FWIW this crude thing works quite well other than volume seemingly being broken/ignored in the sdk function, no fade this way

bool speaker_stream_open(SpeakerPcmFormat format, uint8_t volume);

The 2nd blank at the end is needed or some gets cut off…

static void play_hour_beep(uint8_t volume) {
  int8_t buffer_beep[128];
  int8_t buffer_nothing[128] = {0};

  speaker_stream_open(SpeakerPcmFormat_16kHz_8bit, volume);

  bool is_high = false;
  for(uint8_t i = 0; i < sizeof(buffer_beep); i++) {
    if(i % 2)
      is_high = !is_high;
    buffer_beep[i] = is_high ? 127 : -128;
  }

  for(uint8_t j = 0; j < 2; j++) {
    for (uint8_t i = 0; i < 14; i++) {
      speaker_stream_write(buffer_beep, sizeof(buffer_beep));
    }
    for (uint8_t i = 0; i < 14; i++) {
      speaker_stream_write(buffer_nothing, sizeof(buffer_nothing));
    }
  }
  speaker_stream_close();
}
1 Like

Thanks for enlightening me!

I still can’t get sound to work on my P2D. Strange indeed!

1 Like