0

So far I can make an assembly program to play a song, by telling it what frequency and tempo (how long it should last) each music note should play.

Theoretically, I can output any sound if I know its frequency and tempo. But how do I find out those parameters from a recording (of the human voice/speaking a sentence)?

I'm programming on a micro:bit v2, but I need to program in assembly, not python or scratch.

Is there any assembly lib I can use?

Or is there any tool that can help me reverse engineer (the frequency and tempo) of any sound/music?

It doesn't need to sound real, just need to be recognisable, I'm making a game.

It doesn't have to be a voice, can be a sound effect.

Mzq
  • 1,796
  • 4
  • 30
  • 65
  • What architecture, operating system, and possibly sound chip are you programming for? – fuz May 02 '22 at 10:01
  • Sound file formats (WAV, MP3, OGG etc) contain in their header metainformation specifying the **bitrate** used when they were recorded. – vitsoft May 02 '22 at 10:32
  • i don't know how bitrate is related to the sound frequency or tempo @vitsoft – Mzq May 02 '22 at 12:05
  • 3
    Producing speech sound waves manually is not an easy task, **at all**. It's not just about knowing the right frequency, you have overlapping frequencies and audio patterns that blend together. There is a reason why producing speech digitally is handled by research projects. Your best (and since you're here asking, I daresay your *only*) option is to find a readymade library that handles the task. – Lasse V. Karlsen May 02 '22 at 12:06
  • is there any assembly lib I can use? or some tool to help me reverse engineer a computer synthetic voice? – Mzq May 02 '22 at 12:15
  • 2
    Yes, obviously you can in theory. The easiest way would be by compiling an existing speech synthesizer written in C or C++. If you just want to call a library from an assembly program, it doesn't have to be an "assembly library"; anything that can be called from C can be fairly easily called from asm. At most needing to dig some constants out of a `.h`. (Just noticed you mentioned a non-mainstream system, BBC microbit. If there aren't C compilers that target it, you might have a lot of work to do implementing open-source C code (or algorithm descriptions) by hand.) – Peter Cordes May 02 '22 at 12:26
  • 2
    Ok, https://tech.microbit.org/hardware/ says Microbit runs on an ARM Cortex-M4 microcontroller at 64MHz, with 128KiB of RAM and 512KiB of Flash. So you don't have a lot of space for digital samples, and it's not a fast CPU. But at least it's a real ISA, and a fully mainstream one at that, with excellent support from GCC and clang. (`gcc -Os -mcpu=cortex-m4 -c foo.c`). You might get it to run some simplistic fairly robotic-sounding text to speech, but that's a tiny amount of RAM for digital audio buffers. Hard-realtime with low latency can get away with small buffers, though. – Peter Cordes May 02 '22 at 12:36
  • Or wait, you just mean a single fixed sentence, not turning arbitrary text into speech on the fly. Yeah some kind of compressed sample might do the trick, maybe 8-bit 8kHz sample-rate PCM, maybe with a-law or u-law encoding (https://en.wikipedia.org/wiki/A-law_algorithm) to get slightly better fidelity but still being very cheap to decode on the fly. Or maybe a full decoder for a voice codec, maybe one simpler than Opus though. (https://en.wikipedia.org/wiki/List_of_codecs#Voice). e.g. Speex if you can get its code and the samples you want to fit in your flash storage. – Peter Cordes May 03 '22 at 04:44
  • I'm assuming micro:bit has PCM audio playback (digitally sampled like a WAV file), not just a tone-generator where you program a frequency and duration for sine waves or square waves or whatever. If that's all, then it's like an old IBM-PC speaker and you might want to look at techniques mentioned on retrocomputing like [Was it possible programmatically to manipulate the volume as well as the pitch on computers with no sound chip?](https://retrocomputing.stackexchange.com/q/14655) / [Did playing sounds on the PC speaker keep the CPU busy?](https://retrocomputing.stackexchange.com/q/15341) – Peter Cordes May 03 '22 at 04:49

0 Answers0