[Tutorial][Intermediate]2.Pokitto sound synthesizer


#1

Pokitto SynthTest

This demo shows how to make “ground up” sounds by directly controlling the Pokitto oscillators.
Attention!:
Watch your ears! If you put headphones on and max volume, it can be very loud!

https://os.mbed.com/teams/Pokitto-Community-Team/code/SynthTest/

Project settings (My_settings.h)

#ifndef MY_SETTINGS_H
#define MY_SETTINGS_H

#define PROJ_HIRES 0            //1 = high resolution (220x176) , 0 = low resolution fast mode (110x88)
#define PROJ_ENABLE_SOUND 1     // 0 = all sound functions disabled
#define PROJ_ENABLE_SYNTH 1

#endif

SynthTest.cpp

#include "Pokitto.h"
#include "Synth.h"

Pokitto::Core game;
Pokitto::Display disp;
Pokitto::Sound snd;
Pokitto::Buttons btn;

int tonefreq=33;
uint8_t amplitude = 255;//127;
uint8_t wavetype = 1, arpmode=0;
uint32_t changed = 1;
char notestr[6];
uint8_t sbindx=0,sbx=0,prevy=0;

int main()
{
    game.begin();
    snd.setVolume(snd.getMaxVol()); // volume to max level depending on headset/speaker safety level
    disp.persistence = true;
    disp.color=wavetype+1;
    disp.bgcolor=0;
    uint8_t sbindx=0;
    int oldvol=0;
    int linecenter = (disp.height/4)-10; // center oscilloscope line vertically
    snd.ampEnable(1);
    snd.playTone(1,tonefreq,amplitude,wavetype,arpmode);
    // want to have 2 oscillators 1 octave apart ?
    // snd.playTone(2,tonefreq+12,amplitude,wavetype,arpmode);

    disp.clear();
    disp.print("Frq:");
    getNoteString(notestr,tonefreq);
    disp.println(notestr);
    disp.print("Vol:");
    disp.println((int)amplitude);
    disp.print("Wav:");
    disp.print((int)wavetype);
    switch (wavetype) {
    case 0:
        disp.println(" Off");break;
    case 1:
        disp.println(" Square");break;
    case 2:
        disp.println(" Saw");break;
    case 3:
        disp.println(" Triang");break;
    case 4:
        disp.println(" Noise");break;
    case 5:
        disp.println(" SqNois");break;
    }
    disp.print("HWvol:");
    disp.println((int)snd.getVolume());
    disp.lcdRefresh(disp.screenbuffer);

    while (game.isRunning()) {

        #ifdef POK_SIM
            #define DEBOU 2048*32
        #else
            #define DEBOU 256
        #endif

        if (changed == 0) {
            if(btn.upBtn()) { amplitude++; changed = DEBOU; }
            if(btn.downBtn()) { amplitude--; changed = DEBOU; }
            if(btn.leftBtn() && (tonefreq > 0)) { tonefreq --; changed = DEBOU; }
            if(btn.rightBtn() &&  (tonefreq < 88)) { tonefreq ++; changed = DEBOU; }
            if(btn.released(BTN_A) && wavetype > 0 ) { wavetype--; changed = DEBOU*10;}
            if(btn.released(BTN_B) && wavetype < 5 ) { wavetype++; changed = DEBOU*10;}
            if (snd.getVolume() != oldvol) changed=DEBOU;

            if (changed) {
                    disp.clear();
                    disp.color=0;//owavetype+1;
                    disp.fillRectangle(0,0,109,34);
                    disp.color=wavetype+1;
                    disp.bgcolor=0;
                    disp.print("Frq:");
                    getNoteString(notestr,tonefreq);
                    disp.println(notestr);
                    disp.print("Vol:");
                    disp.println((int)amplitude);
                    disp.print("Wav:");
                    disp.print((int)wavetype);
                    switch (wavetype) {
                    case 0:
                        disp.println(" Off");break;
                    case 1:
                        disp.println(" Square");break;
                    case 2:
                        disp.println(" Saw");break;
                    case 3:
                        disp.println(" Triang");break;
                    case 4:
                        disp.println(" Noise");break;
                    case 5:
                        disp.println(" SqNois");break;
                    }
                    disp.print("HWvol:");
                    disp.println((int)snd.getVolume());
                    snd.playTone(1,tonefreq,amplitude,wavetype,arpmode);
                    oldvol = (int) snd.getVolume();
                    // want to have 2 oscillators 1 octave apart ?
                    // snd.playTone(2,tonefreq+12,amplitude,wavetype,arpmode);
            }
        } else changed--;
        disp.color=0;
        disp.drawColumn(sbx,38,disp.height);
        disp.color=wavetype+1;
        uint8_t tindex = sbindx*2;
        int16_t y = linecenter + (((int)128-(soundbuf[tindex]))>>1);
        disp.drawLine(sbx-1,prevy,sbx,y);
        game.update();
        disp.color=0;
        prevy=y;
        sbx++;sbindx++;
        if (sbx>disp.width-1) {sbx=0;}
    }
    return 0; // good manners!
}


Understanding C++, some help please
[Wiki]4.Introduction to Pokitto Sound
#2

So that’s why sound wasn’t working for me! I didn’t know about PROJ_ENABLE_SYNTH. :joy:


#3

#define PROJ_ENABLE_SOUND 1 gives me:
Error: Identifier "min2" is undefined in "PokittoLib/POKITTO_CORE/PokittoSound.cpp", Line: 453, Col: 27

idk if anyone else getting this, but uncomment #define min2(a,b) (((a)<(b))?(a):(b)) in PokittoFakeavr.h

#define PROJ_ENABLE_SYNTH 1 gives errors aswell:
Error: Undefined symbol updatePlaybackSD(unsigned char) (referred from HWSound.LPC11U68.o).