Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:33 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : play simple midi notes

     Page 1 of 2    
Author Message
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 04:34pm 28 Dec 2023
Copy link to clipboard 
Print this post

WebMite MMBasic Version 5.08.00b5
OPTION SYSTEM SPI GP10,GP11,GP12
OPTION WIFI NETGEAR57, **************, PICOE6616408438
OPTION TELNET CONSOLE ON
OPTION AUDIO VS1053 GP2,GP3,GP4,GP9,GP8,GP7,GP6', ON PWM CHANNEL 1

I have gotten my VS1053 board working.  It is connected to my hi fi amplifier
via an audio transformer.  I can get sounds by using play midi test.  It sounds great.
I can't seem to make it work further.

I've tried this simple program



Play MIDI 'enable real time MIDI
Play MIDI cmd &B11000001,10 'set the instrument for channel 1
Play MIDI cmd &B11000010,1 'set the instrument for channel 2
Play note on 1,127,126
Play note on 2,11,12

I get nothing.  I've tried many different combinations of numbers for the play not parameters with no success. can anyone advise?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9115
Posted: 06:25pm 28 Dec 2023
Copy link to clipboard 
Print this post

Your note parameters are a bit extreme

Try "play note on 1,80,127"

Try the attached as a working example

' Plays "The Entertainer" by Scott Joplin
'  - also encodes it as DATA statements for playing outside of this program.
'
' Code Copyright (c) 2022 Thomas Hugo Williams
' License MIT <https://opensource.org/licenses/MIT>
' For MMBasic 5.07.03

Option Base 0
Option Default None
Option Explicit On
Play midi 'enable real time midi
Play midi cmd &B11000001,4 'set the instrument for channel 1
Option Break 4
On Key 3, on_break

Const FILE$ = "entertainer"
Const SZ% = 256
' Const NUM_CHANNELS% = music.prompt_for_num_channels%()
Const NUM_CHANNELS% = 3

Dim channel1%(SZ%), channel2%(SZ%), channel3%(SZ%), channel4%(SZ%)
Dim err$

If Instr(MM.Device$, "PicoMite") Then Save FILE$ + ".bas"

music.compose()
music.process()
music.write_data()
music.play()

End

' Interrupt routine to stop music and restore default Break Key.
Sub on_break
Play Stop
Option Break 3
End
End Sub

' Prompts user for number of channels to encode / play.
Function music.prompt_for_num_channels%()
Local s$
Do
Line Input "How many channels (1-4)? ", s$
Print
Select Case Val(s$)
 Case 1 To 4 : Exit
End Select
Loop
music.prompt_for_num_channels% = Val(s$)
End Function

' Fills channels{1-3}% with musical notes for "The Entertainer".
Sub music.compose()
' ---------- Line 0 ----------

music.parse(channel1%(), "qD4,qD#4")

music.parse(channel2%(), "1-")

music.parse(channel3%(), "1-")

' ---------- Line 1 ----------

music.parse(channel1%(), "qE4,1C5,qE4,1C5,qE4,qC5")
music.parse(channel1%(), "2C5,q-,qC5,qD5,qD#5")
music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qB5,1D5")
music.parse(channel1%(), "3C5,qD4,qD#4")

music.parse(channel2%(), "1C4,1C3,1D#3,1E3")
music.parse(channel2%(), "1F3,1G3,1A4,1B4")
music.parse(channel2%(), "1C4,1E3,1F3,1G3")
music.parse(channel2%(), "1C3,1G3,1C4,qC4,q-")

music.parse(channel3%(), "4-")
music.parse(channel3%(), "4-")
music.parse(channel3%(), "4-")
music.parse(channel3%(), "4-")

' ---------- Line 2 ----------

music.parse(channel1%(), "qE4,1C5,qE4,1C5,qE4,qC5")
music.parse(channel1%(), "3C5,qA5,qG4")
music.parse(channel1%(), "qF#4,qA5,qC5,qE5,qE5,qD5,qC5,qA5")
music.parse(channel1%(), "3D5,qD4,qD#4")

music.parse(channel2%(), "1C4,1C3,1D#3,1E3")
music.parse(channel2%(), "1F3,1G3,1A4,1C#3")
music.parse(channel2%(), "1D3,1F#3,1A4,1D3")
music.parse(channel2%(), "1G3,1F3,1E3,1D3")

music.parse(channel3%(), "4-")
music.parse(channel3%(), "4-")
music.parse(channel3%(), "4-")
music.parse(channel3%(), "4-")

' ---------- Line 3 ----------

music.parse(channel1%(), "qE4,1C5,qE4,1C5,qE4,qC5")
music.parse(channel1%(), "2C5,q-,qC5,qD5,qD#5")
music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qB5,1D5")
music.parse(channel1%(), "2C5,qC5,q-,qC5,qD5")

music.parse(channel2%(), "1C3,1C4,1D#3,1E3")
music.parse(channel2%(), "1F3,1G3,1A4,1B4")
music.parse(channel2%(), "1C4,1E3,1F3,1G3")
music.parse(channel2%(), "1C4,1G3,2C3")

music.parse(channel3%(), "4-")
music.parse(channel3%(), "4-")
music.parse(channel3%(), "4-")
music.parse(channel3%(), "4-")

' ---------- Line 4 ----------

music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qC5,qD5,qC5")
music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qC5,qD5,qC5")
music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qB5,1D5")
music.parse(channel1%(), "2C5,qC5,qE4,qF4,qF#4")

music.parse(channel2%(), "qC5,q-,qC5,q-,qBb5,q-,qBb5,q-")
music.parse(channel2%(), "qA5,q-,qA5,q-,qAb5,q-,qAb5,q-")
music.parse(channel2%(), "qG4,q-,qG4,q-,1G4,1-")
music.parse(channel2%(), "1-,1G3,qC4,q-,1-")

music.parse(channel3%(), "qC4,q-,qC4,q-,qBb4,q-,qBb4,q-")
music.parse(channel3%(), "qA4,q-,qA4,q-,qAb4,q-,qAb4,q-")
music.parse(channel3%(), "qG3,q-,qG3,q-,1G3,1-")
music.parse(channel3%(), "1-,1G2,qC3,q-,1-")

' ---------- Line 5 ----------

music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE4,qF4,qF#4")
music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE5,qC5,qG4")
music.parse(channel1%(), "qA5,qB5,qC5,qD5,qE5,qD5,qC5,qD5")
music.parse(channel1%(), "2G4,qG4,qE4,qF4,qF#4")

music.parse(channel2%(), "1E4,qF4,qE4,qE4,q-,1-")
music.parse(channel2%(), "1E4,qF4,qE4,qE4,q-,1-")
music.parse(channel2%(), "4-")
music.parse(channel2%(), "4-")

music.parse(channel3%(), "1C4,1-,1G3,1-")
music.parse(channel3%(), "1C4,1-,1G3,1-")
music.parse(channel3%(), "2F3,2G3")
music.parse(channel3%(), "1C3,1G3,1C4,1-")

' ---------- Line 6 ----------

music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE4,qF4,qF#4")
music.parse(channel1%(), "1G4,qA5,qG4,qG4,qG4,qA5,qA#5")
music.parse(channel1%(), "1B5,q-,1B5,qA5,qF#4,qD4")
music.parse(channel1%(), "2G4,qG4,qE4,qF4,qF#4")

music.parse(channel2%(), "1E4,qF4,qE4,qE4,q-,1-")
music.parse(channel2%(), "1E4,qF4,qE4,qE4,q-,1-")
music.parse(channel2%(), "4-")
music.parse(channel2%(), "4-")

music.parse(channel3%(), "1C4,1-,1G3,1-")
music.parse(channel3%(), "1C4,1-,1G3,1C#4")
music.parse(channel3%(), "2D4,2D3")
music.parse(channel3%(), "qG3,q-,qG3,q-,1A4,1B4")

' ---------- Line 7 ----------

music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE4,qF4,qF#4")
music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE5,qC5,qG4")
music.parse(channel1%(), "qA5,qB5,qC5,qD5,qE5,qD5,qC5,qD5")
music.parse(channel1%(), "2C5,qC5,qG4,qF#4,qG4")

music.parse(channel2%(), "1E4,qF4,qE4,qE4,q-,1-")
music.parse(channel2%(), "1E4,qF4,qE4,qE4,q-,1-")
music.parse(channel2%(), "4-")
music.parse(channel2%(), "4-")

music.parse(channel3%(), "1C4,1-,1G3,1-")
music.parse(channel3%(), "1C4,1-,1G3,1-")
music.parse(channel3%(), "2F3,2G3")
music.parse(channel3%(), "1C3,1G3,1C4,1-")

' ---------- Line 8 ----------

music.parse(channel1%(), "1C5,qA5,qC5,qC5,qA5,qC5,qA5")
music.parse(channel1%(), "qG4,qC5,qE5,qG5,qG5,qE5,qC5,qG4")
music.parse(channel1%(), "1A5,1C5,qE5,1D5,qD5")
music.parse(channel1%(), "3C5,1-")

music.parse(channel2%(), "qF4,q-,qF4,q-,qF#4,q-,qF#4,q-")
music.parse(channel2%(), "qG4,q-,qG4,q-,qE4,q-,qE4,q-")
music.parse(channel2%(), "qF4,q-,qF4,q-,qG4,q-,qG4,q-")
music.parse(channel2%(), "1C5,1G4,1C4,1-")

music.parse(channel3%(), "qF3,q-,qF3,q-,qF#3,q-,qF#3,q-")
music.parse(channel3%(), "qG3,q-,qG3,q-,qE3,q-,qE3,q-")
music.parse(channel3%(), "qF3,q-,qF3,q-,qG3,q-,qG3,q-")
music.parse(channel3%(), "1C4,1G3,1C3,1-")
End Sub

' Parses comma separated list of notes.
'
' @param channel%() parsed notes are appended to this array.
' @param s$     comma separated list.
Sub music.parse(channel%(), s$)
Local s_idx% = 1
Local ch$ = ","
Do While ch$ = ","
If music.parse_note%(channel%(), s$, s_idx%) <> 0 Then
 Error err$ + " : s_idx = " + Str$(s_idx%)
EndIf
Inc s_idx%
ch$ = Mid$(s$, s_idx%, 1)
Inc s_idx%
Loop
End Sub

' Parses single note.
'
' @param channel%() parsed note is appended to this array.
' @param s$     note is parsed from this string ...
' @param s_idx%   ... starting at this index. On exit this will
'           contain the index of the last character parsed.
' @return       0 on success, -1 on error. Error message will
'           be in the global err$ variable.
Function music.parse_note%(channel%(), s$, s_idx%)
music.parse_note% = -1
Local i%
Local ch$ = Mid$(s$, s_idx%, 1)

' Parse duration.
Local duration%
Select Case ch$
Case "q": duration% = 1
Case "1", "2", "3", "4": duration% = 2 * Val(ch$)
Case Else
 err$ = "Syntax error: expected duration"
 Exit Function
End Select

Inc s_idx%
ch$ = Mid$(s$, s_idx%, 1)

' Parse note.
Local n% = 0 ' 0 = Rest, 1 = A0
Select Case ch$
Case "A" : n% = 1
Case "B" : n% = 3
Case "C" : n% = 4
Case "D" : n% = 6
Case "E" : n% = 8
Case "F" : n% = 9
Case "G" : n% = 11
Case "-" : ' Do nothing
Case Else
 err$ = "Syntax error: expected note"
 Exit Function
End Select

If n% = 0 Then
For i% = 1 To duration%
 LongString Append channel%(), Chr$(0)
Next
music.parse_note% = 0
Exit Function
EndIf

Inc s_idx%
ch$ = Mid$(s$, s_idx%, 1)

' Parse b or #.
Local off% = 0
Select Case ch$
Case "b" : off% = -1
Case "#" : off% = 1
End Select
If off% <> 0 Then
Inc n%, off%
Inc s_idx%
ch$ = Mid$(s$, s_idx%, 1)
EndIf

' Parse octave.
If Not Instr("012345678", ch$) Then
err$ = "Syntax error: expected octave"
Exit Function
EndIf
Inc n%, 12 * Val(ch$)

' Write note into buffer.
For i% = 1 To duration%
LongString Append channel%(), Chr$(n%)
Next

music.parse_note% = 0
End Function

' Combines the individual channels into a single global music%() array.
Sub music.process()
' Terminate each channel with 255 and determine the maximum length.
Local max_len% = 0, i%, j%
For i% = 1 To NUM_CHANNELS%
Execute "LongString Append channel" + Str$(i%) + "%(), Chr$(&hFF)"
max_len% = Max(max_len%, Eval("LLen(channel" + Str$(i%) + "%())"))
Next

' Pad max_len% to be a multiple of 8.
Do While max_len% Mod 8 > 0 : Inc max_len% : Loop

' Pad each channel with 255 until all the same length.
For i% = 1 To NUM_CHANNELS%
Do While Eval("LLen(channel" + Str$(i%) + "%())") < max_len%
 Execute "LongString Append channel" + Str$(i%) + "%(), Chr$(&hFF)"
Loop
Next

' Combine the channels into a single music buffer.
Dim music%(1 + (NUM_CHANNELS% * max_len% / 8))
For i% = 0 To max_len% - 1
For j% = 1 To NUM_CHANNELS%

 Execute "LongString Append music%(), Chr$(LGetByte(channel" + Str$(j%) + "%()
, i%))"
Next
Next
End Sub

' Writes music%() array into a file as DATA statements.
Sub music.write_data()
Local count% = 0, i%, p% = Peek(VarAddr music%()) + 8
Open "entertainer.inc" For Output As #1
Print #1, "Data " Format$(LLen(music%()), "%-6g") "' Number of bytes of music d
ata."
Print #1, "Data " Format$(NUM_CHANNELS%,"%-6g") "' Number of channels."
For i% = 0 To LLen(music%()) - 1 Step 8
Print #1, Choice(count% = 0, "Data ", ", ");
Print #1, "&h" Hex$(Peek(Integer p%), 16);
Inc p%, 8
Inc count%
If count% = 4 Then Print #1 : count% = 0
Next
Close #1
End Sub

' Plays the contents of the music%() array using interrupts.
Sub music.play()
Dim music_ptr% = Peek(VarAddr music%()) + 8
'Play SOUND 1,B,s,155.5634919
SetTick 200, music.play_interrupt, 1
Do While music_ptr% <> 0 : Loop
End Sub

' Interrupt routine playing a single half-beat (per channel) from the music%()
array.
Sub music.play_interrupt()
Local i%, n%, halted% = 0
Static nlast%(NUM_CHANNELS%)
Local f!
For i% = 1 To NUM_CHANNELS%
n% = Peek(bp music_ptr%)
Select Case n%
 Case 0
'   Play Sound i%, B, O
  Play note off 1,nlast%(i%)
  nlast%(i%)=0
  Print Str$(i%) ": Rest"
 Case 1 To 254
  f!=440 * 2^((n% - 49) / 12.0)
  Print Str$(i%) ":" f! " hz",n%, nlast%(i%)
  If n%<>nlast%(i%) Then Play note on 1,n%,127
  nlast%(i%)=n%
'   Play Sound i%, B, T, f!, 15
 Case 255
  Play note off 1,nlast%(i%)
'  Play Sound i%, B, O
  Print Str$(i%) ": Halted"
  Inc halted%
End Select
' Inc music_ptr%
Next
If halted% = NUM_CHANNELS% Then music_ptr% = 0 ' Halt
End Sub

Edited 2023-12-29 04:26 by matherp
 
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 06:35pm 28 Dec 2023
Copy link to clipboard 
Print this post

thank you
I tried 1,80,127.  Just got a click sound. I tried running the program, still just a click. I immediately tried play midi test 2, and got all the different sounds.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9115
Posted: 06:42pm 28 Dec 2023
Copy link to clipboard 
Print this post

Just tried it on a WebMite and works fine

Attached is the firmware I'm using just in case

If you use PLAY MIDI TEST then make sure you set it back to normal afterwards

PLAY MIDI TEST 0


PicoMiteWeb.zip
Edited 2023-12-29 04:45 by matherp
 
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 07:15pm 28 Dec 2023
Copy link to clipboard 
Print this post

I just loaded your .UF2 file.  same result. just a "click".  But the play midi test works fine.
 
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 07:17pm 28 Dec 2023
Copy link to clipboard 
Print this post

N:72
N:73
N:74
N:75
N:76
N:77
N:78
N:79
N:80
N:81
N:82
N:83
N:84
N:85
N:86
> play midi test 0
Error : 0 is invalid (valid is 1 to 3)
> play midi test 0
Error : Midi output not enabled
> play midi
Real Time MIDI mode enabled
> play midi test 0
Error : 0 is invalid (valid is 1 to 3)
>if I try to turn off midi test with a "0" it tells me its invalid
 
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 07:25pm 28 Dec 2023
Copy link to clipboard 
Print this post

I interupted the midi test with crtl brk

typed in play midi test 0
I got midi not enabled as a result
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9115
Posted: 07:32pm 28 Dec 2023
Copy link to clipboard 
Print this post

Power the Pico and VS1053 off completely. Then DON'T use test. Just play the file I attached. If that doesn't work I don't know what to suggest as I've tested thoroughly. The VS1053 can be forced into different modes depending on the wiring but I can't see how the test would work but not the real-time as they use the same code.
 
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 07:37pm 28 Dec 2023
Copy link to clipboard 
Print this post

[324] Execute "LongString Append music%(), Chr$(LGetByte(channel" + Str$(j%) + "%()"
Error : Expected closing bracket
>

ran program but got this error on line 324
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 07:51pm 28 Dec 2023
Copy link to clipboard 
Print this post

  crazycloud said  ran program but got this error on line 324


Note that that line is broken in two. Delete the carriage return at the end to combine back to one line.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 08:28pm 28 Dec 2023
Copy link to clipboard 
Print this post

error is now corrected.  Still just a "click" I have 2 other VS1053 boards. I also have a VS1053 shield that I got from ADAFRUIT. Its meant to be used with an Aurdino.
I will try the other hardware tonight. Thank you for all the work you do here. Its very awesome hardware and software.
 
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 08:49pm 28 Dec 2023
Copy link to clipboard 
Print this post

It's working. Your entertainer program is playing.  I have no idea what I did to make it work.  The last thing I did was remove 2 carriage returns from the listing.  I also had it powered off for about 5 minutes.   GREAT SOUND!!!!!
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4038
Posted: 08:12pm 29 Dec 2023
Copy link to clipboard 
Print this post

Hi @crazycloud,

Thanks for the coffees .

"The Entertainer" program of mine that Peter posted seems to be of fairly early vintage, and note he has "hacked" it somewhat (to use the Midi support) most significantly replacing PLAY SOUND with PLAY NOTE.

There is a more elaborate version of the original program with 5 tunes here: https://github.com/thwill1000/mmbasic-sptools/blob/master/src/spmusic/spmusic.bas

But it would need equivalent "hacking" for Midi, and I don't have the board to troubleshoot that for you. Could someone point me at a link to a known working board and perhaps I'll get one.

Best wishes,

Tom
Edited 2023-12-30 06:19 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6786
Posted: 08:25pm 29 Dec 2023
Copy link to clipboard 
Print this post

PicoGAME 4 will be out soon in a CMM2-size format. This is the type that it will use:

The red one

Note: male pins should be fitted from the Top of the board so it can be plugged in upside down. It came with no pins fitted.

At the moment I can't confirm that it works. :)
.
Edited 2023-12-30 06:26 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 08:42pm 29 Dec 2023
Copy link to clipboard 
Print this post

the exact midi board I used is this one

https://www.amazon.com/HiLetgo-Recording-Microphone-Interface-12-288Mhz/dp/B07XCN3C7B/ref=sr_1_1_sspa?crid=P0892AAMM16X&keywords=vs1053+mp3+module&qid=1703882019&sprefix=vs1053%2Caps%2C288&sr=8-1-spons&sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&psc=1




don't connect the output to anything with a ground. I blew up my first board!
I have the out put connected to a cheap audio transformer

this one

https://www.amazon.com/dp/B09KGXSJ12?psc=1&ref=ppx_yo2ov_dt_b_product_details


I'll try the other program now.  The input is much appreciated.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4038
Posted: 12:02am 30 Dec 2023
Copy link to clipboard 
Print this post

Does Peter's Midi version of "The Entertainer" sound "off" ? It *looks* like he is treating my note encoding as if it were the Midi note encoding, but I don't believe it is, it is offset (and it appears that the original and newer versions of my code used different offsets - scratches head) .

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
crazycloud
Newbie

Joined: 20/08/2023
Location: United States
Posts: 37
Posted: 12:57pm 30 Dec 2023
Copy link to clipboard 
Print this post

Good Morning.  When you say "off" do you mean the notes are off frequency?  It sounds
accurate but I don't have anything to compare it to.

I'm studying the snippets of code like this one

"Play note off 1,nlast%(i%)
 nlast%(i%)=0
 Print Str$(i%) ": Rest"
Case 1 To 254
 f!=440 * 2^((n% - 49) / 12.0)
 Print Str$(i%) ":" f! " hz",n%, nlast%(i%)
 If n%<>nlast%(i%) Then Play note on 1,n%,127
 nlast%(i%)=n%
'   Play Sound i%, B, T, f!, 15"  

to see how the notes are translated into midi notes.
I see where regular play is commented out.

I just started using a program called "noteworthy composer".  You can import a .mid file. As it plays a staff is displayed on top with the notes.  On the bottom is an 88
key keyboard that indicates what notes are being played.  It looks like this.







I have a image that shows what keys are the equivalent midi note.  But this is kind of convoluted.  The equation method is much better. I'm having a lot of fun  playing the entertainer with many different instruments.  I have an extremely large collection of .mid files that could be used in games.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9115
Posted: 02:06pm 30 Dec 2023
Copy link to clipboard 
Print this post

Tom's code was just a very simple way of my testing real-time midi. I have no idea if the note mapping is correct but if it isn't then I think it just plays in a different key i.e. it transposes the music
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4038
Posted: 02:25pm 30 Dec 2023
Copy link to clipboard 
Print this post

The "octave" rather than the "key" is different.

In the "MIDI note encoding" Middle-C (C4, 261.63Hz) is note 60.

In the version of "The Entertainer" code in this thread, C4 is encoded as note 52 (C3, 263.74Hz in MIDI), so as luck would have it, it is exactly one octave lower, hence it still sounds OK.

However in the later version I linked to on github, C4 is encoded as note 49 ... so it will sound rather funky when played via MIDI without being transposed.

Now that I've become aware of the MIDI standard I will look at changing my code to adhere to it when I find the opportunity ... I'll be spending some of my coffee money on one of those boards.

Best wishes,

Tom
Edited 2023-12-31 00:39 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9115
Posted: 02:53pm 30 Dec 2023
Copy link to clipboard 
Print this post

  Quote  In the "MIDI note encoding" Middle-C (C4, 261.63Hz) is note 60.

In the version of "The Entertainer" code in this thread, C4 is encoded as note 52 (C3, 263.74Hz in MIDI), so as luck would have it, it is exactly one octave lower,


How many tones in an octave?  
 
     Page 1 of 2    
Print this page
© JAQ Software 2024