Minimal MIDI decoder

Designing hardware that uses VLSI Solution's devices as slave codecs such as an external MP3 decoder chip for a host microcontroller.
Davidelvig
Senior User
Posts: 39
Joined: Mon 2015-08-24 5:25

Re: Minimal MIDI decoder

Post by Davidelvig »

I'll check back. September?

As for one of my other questions.... are you the person for that?

I have only exposed XCS (23) to the microprocessor (and not XDCS (13) which is tied LOW). With that in mind, can I still send SDI data to the VS1053 by setting SM_SDISHARE=1, and then sending SDI data (e.g. MIDI commands)? The data sheet refers to the SM_SDISHARE causing XDCS to appear as an inverted XCS. Does that change my chip select logic? i.e. when I use SCI, I pull XCS low. Would I still do that when using SDI and SM_SDISHARE=1? from the Data Sheet (7.1.1): "If SM_SDISHARE is 1, pin XDCS is not used, but the signal is generated internally by inverting XCS."
User avatar
Panu
VSDSP Expert
Posts: 2816
Joined: Tue 2010-06-22 13:43

Re: Minimal MIDI decoder

Post by Panu »

Hi!

Yes, but note the inverted XCS. You can send both SCI and SDI data with just the XCS chip select by setting SCIMODE_SHARED bit before sending SDI data. The procedure is:

1) Pull XCS low
2) Set SM_SHARED bit in SCI_MODE register to "1"
3) Pull XCS High
3) Send SDI data bytes
4) Pull XCS low
5) 2) Set SM_SHARED bit in SCI_MODE register to "0"
6) Pull XCS high


If nothing else is connected to the SPI bus, then you can just keep the VS in the SHARED mode.

-Panu
Davidelvig
Senior User
Posts: 39
Joined: Mon 2015-08-24 5:25

Re: Minimal MIDI decoder

Post by Davidelvig »

Thank you, Panu!
I'll await Pasi's help on the MIDI file methods.
User avatar
Panu
VSDSP Expert
Posts: 2816
Joined: Tue 2010-06-22 13:43

Re: Minimal MIDI decoder

Post by Panu »

Oh, just noticed you have xdcs low, that is bad. Please pull it high!

-panu
Davidelvig
Senior User
Posts: 39
Joined: Mon 2015-08-24 5:25

Re: Minimal MIDI decoder

Post by Davidelvig »

I do indeed have XDCS pulled low. Hmmm.
SCI still seems to work, but I'm assuming SDI will not work.

I'll await redoing the board until I heart from Pasi about other possible changes with respect to MIDI file processing.

Thanks!
User avatar
pasi
VLSI Staff
Posts: 1783
Joined: Thu 2010-07-15 16:04

Re: Minimal MIDI decoder

Post by pasi »

Davidelvig wrote: Fri 2017-08-11 6:28Can you link me to a microcontroller source code example for playing a midi file on the VS1053 through SDI?
(I'm using arduino c++, but any source language will do.)
MIDI file is played like a file of any other audio format. There are a few code examples by Henrik here somewhere. ( viewtopic.php?f=11&t=840 )

The MIDI file needs to be format 0 though. You can find a simple format 1 to format 0 converter from http://www.vlsi.fi/en/support/software/vs10xxtools.html .

If you need to interleave playing of a MIDI file and real-time MIDI notes, you need special processing.
1) Play in decoder mode: insert midi messages to the file data - you would need to adjust the MIDI file size fields, parse tempo and reformat timing information to be able to insert notes, and keep the SDI FIFO as empty as possible to keep the inserted notes as real-time as possible.
2) Play in real-time MIDI mode: parse the MIDI file (including tempo and timing information), and send the MIDI messages as real-time data when specified in the file, and insert real-time notes from the user.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
Davidelvig
Senior User
Posts: 39
Joined: Mon 2015-08-24 5:25

Re: Minimal MIDI decoder

Post by Davidelvig »

pasi wrote: Tue 2017-08-29 13:04 MIDI file is played like a file of any other audio format. There are a few code examples by Henrik here somewhere. ( viewtopic.php?f=11&t=840 )
Thanks, Pasi.
I've used the examples, and am getting no errors, but can't get files playing directly through SDI yet.

I have a board with Real-Time MIDI set at startup (GPIO0 is tied low and GPIO1 is tied high.)

I can play MIDI messages one by one and it plays well.
I'm doing this by parsing the MIDI Type 0 file, and playing the messages into the VS1053 through the Rx pin at MIDI rates.

I'd like to offer the option to play the file directly.

I'm using this method to write to the SDI interface:

Code: Select all

int WriteSDI(const uint8_t *data, uint8_t bytes) {
    if (bytes > 32) {
         Serial.printf("Request to WriteSDI is limited to 32 bytes. Requested bytes was %d\n", bytes);
         return(-1);
    }
    int ret = 0;
    ret = waitForDREQ(10);
    spiOn(VS1053_DataSlaveSelectPin);
    for (int x = 0; x < bytes; x++) {
         Serial.printf("WriteSDI(): %c\t%d\t\t",data[x], data[x]);
         char c = SPI.transfer(data[x]);
         Serial.printf("SPI Returns: %c\t%d\n", c, c);
    }
    spiOff(VS1053_DataSlaveSelectPin);
    ret = waitForDREQ(10);
    return(ret);
}

int waitForDREQ(unsigned int msWaitTime) {
    unsigned long startTime = millis();
    int ret = 0;
    
    while (!digitalRead(VS1053_DREQPin)) {
        yield();
        if (millis() - startTime > msWaitTime) {
             ret = -1;
             Serial.printf("Timed out waiting %dms for DREQ to return to HI value.\n", msWaitTime);
             break;
        }
    }
    return(ret);
}

I can see the correct bytes arriving to the WriteSDI() method through the Serial.printf statement.
Also, waitForDREQ() appears to succeed;

SPI returns (int)255 in all writes.
No sound plays.

Do I need to do some SCI setup before using SDI in this case? i.e. do some registers need to be changed?
Can I have Real-Time MIDI at start-up, and then do file decoding later?

Thanks
Dave
User avatar
pasi
VLSI Staff
Posts: 1783
Joined: Thu 2010-07-15 16:04

Re: Minimal MIDI decoder

Post by pasi »

If you want to play files, you need to start the decoder in normal decoding mode instead of in Real-Time MIDI mode.

Because the board is wired for RTMIDI (GPIO0 and GPIO1 fixed), you would need a small start code to load through SCI.
Visit https://www.facebook.com/VLSISolution VLSI Solution on Facebook
Davidelvig
Senior User
Posts: 39
Joined: Mon 2015-08-24 5:25

Re: Minimal MIDI decoder

Post by Davidelvig »

OK, thanks.
I've seen reference to a "small start code" in the Datasheet

Code: Select all

9.10 Real-Time MIDI
If GPIO0 is low and GPIO1 is high during boot, real-time MIDI mode is activated. In this mode the PLL is configured to 4.0×, the UART is configured to the MIDI data rate 31250 bps, and real-time MIDI data is then read from UART and SDI. Both input methods should not be used simultaneously. If you use SDI, first send 0xff and then send the MIDI data byte.
EarSpeaker setting can be configured with GPIO2 and GPIO3. The state of GPIO2 and GPIO3 are only read at startup.
Real-Time MIDI can also be started with a small patch code using SCI.
In the Datasheet's case - it is how to get into Real-time MIDI mode.
Sounds like I'd use a "start code" in either direction.

How can I find the Start Codes needed, and instruction on when to load them...
e.g.
- to turn Real-Time MIDI on, load start code "X" using SCI, then initiation a Software Reset
- to turn Real-Time MIDI off, load start code "Y" using SCI, then initiation a Software Reset
Davidelvig
Senior User
Posts: 39
Joined: Mon 2015-08-24 5:25

Re: Minimal MIDI decoder

Post by Davidelvig »

@pasi, can you point me at the documentation showing how to get a VS1053 into and out of Real-Time MIDI mode using SCI commands?
- and let me know if this can be done after start-up, even if GPIO0 is tied low and GPIO1 is tied high.

Thanks
Dave
Post Reply