Tsunami program flow

I’m playing a track (in Python) then checking when the track has finished playing.
It appears that the while loop is not executed until the track is finihed playing.

Any suggestions?

He is the high level code:
import TsunamiCore as tc
import time

port = “/dev/ttyUSB0”
tc.OpenPort(port)
####################### start of composition ###############################################
tc.PlayPoly(8,1) # call track control routine trck 8 output 1
while tc.TrackPlaying(8):
print(“true”)
####################### end of composition ###############################################
tc.StopAll()
tc.ClosePort(port)

The output is:
Polyphonic Play command for track 8 sent to output 1
Track 1 is False
Stop All command sent

Closing connection on /dev/ttyUSB0…

It’s probably due to ‘blocking’ code

I’d normally just advise to use the configurator app to chain tracks without software intervention Tsunami Hookup Guide - SparkFun Learn …something like:

[Trigger1]
Function=Normal
Output=1
Track=8
Polyphonic=1

This approach offloads playback control to Tsunami’s internal scheduler via INI file, eliminating the need for software polling.

Otherwise, you have a few options…the main one I’d suggest is to use threading (because you’re using Python already) to run the audio playback in a separate thread, something like:

import threading

# Start playback in a thread
play_thread = threading.Thread(target=tc.PlayPoly, args=(8,1))
play_thread.start()

# Now the main thread can monitor playback
while tc.TrackPlaying(8):
    print("true")
    time.sleep(0.1)  # Add a small delay to avoid CPU hogging

Let me know things shake out!

It appears to be an issue in how I’ve implement isTrackplaying, which nickhayeck did not implement. There is a difference in how this routine is implemented in the Qwiic version and the serial version. Since I am using the serial interface is that the code to follow?

Also is there code which shows an example of the SET_INPUT_MIX?

Threading doesn’t seem to do the trick. See following code and output.
import TsunamiCore as tc
import time
import threading

port = “/dev/ttyUSB0”
tc.OpenPort(port)
tc.Info()
####################### start of composition ###############################################
#Start playback in a thread
play_thread = threading.Thread(target=tc.Play, args=(7,1))
play_thread.start()
while tc.TrackPlaying(7):
print(“true”)
time.sleep(0.1) # Add a small delay to avoid CPU hogging
####################### end of composition ###############################################
tc.StopAll()
tc.ClosePort(port)

Output:

Play command for track 7 sent to output 1
Get Status sent b’\x07\x00U’
Track 7 is stopped
Stop All command sent

Closing connection on /dev/ttyUSB0…

Darn, I thought that might work

There’s really just the demo Tsunami-Arduino-Serial-Library/examples/TsunamiDemo/TsunamiDemo.ino at master · robertsonics/Tsunami-Arduino-Serial-Library · GitHub and then the guides

https://static1.squarespace.com/static/62ab6e0d1f3ea036834d4a0b/t/63c3320ae629af326157fe3a/1673736723795/Tsunami_UserGuide_20230114.pdf - pg 13 has info about SET_INPUT_MIX

I can’t help with the Python implementation, but I thought I’d explain how track reporting works and why it’s a different mechanism in the Qwiic library than in the Serial library.

The serial library was developed for the original version of Tsunami which didn’t have a Qwiic interface. I was concerned that if I provided a serial command to ask whether a particular track is playing, people would poll way too often and potentially interfere with audio playback. So I instead provided an way to enable track reporting, which means that Tsunami will send a serial message whenever any track starts or stops. The serial library handles these messages and maintains a table of what tracks are playing. So when you ask if a track is playing, the library simply refers to this table without having to send a message to, and get a response from, Tsunami.

With Qwiic (I2C) protocol, the slave (Tsunami) can’t just send an unsolicited message - it can only respond to a request from the master, so this kind of track reporting is not possible. Therefore, the Qwiic library does in fact contain a command to ask if a specific track is playing which sends a Qwiic command and requires a response.

1 Like

Thank you robertsonics for your time and input. At this point, I believe that I have finished programming and debugging all the features of the board in Python using the serial interface, including the isTrackPlaying function. I’ll clean up some of the code and document so I can offer it to others.

I decided to go with the serial interface in Python since I has the framework from nickhayeck. As a more an artist then programmer, it was a easier path and I have fixed some of nick’s bugs and added missing features. Since I am awaiting funding for my project, perhaps I’ll embark on creating an I2C version.

2 Likes

Here is a link to the finished serial Tsunami interface. Feel free to test and publish.

I’ve connected my Tsunami via i2c and will try to make a Python version, but its been a while since I used C, so I might have a few questions if you can handle it.

2 Likes

I have the Python program running the Tsunami using the qwiic_i2c library. I’m able to read and write to the Tsunami. My current issue is that the receive buffer in not clearing out. I’ll post the issue in the proper forum.

1 Like