Skip to content

Commit

Permalink
Allow to stop/play a new sound before the end of the previous one in …
Browse files Browse the repository at this point in the history
…the SFX editor.
  • Loading branch information
dwursteisen committed Feb 27, 2024
1 parent 58236c7 commit e332066
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ abstract class SoundManager {
}
}

fun playSong(song: Song) {
val (mix, numberOfSamples) = createBufferFromSong(song)

playBuffer(mix, numberOfSamples)
}

fun playSong(song: Song2) {
val (mix, numberOfSamples) = createBufferFromSong(song)
playBuffer(mix, numberOfSamples)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.minigdx.tiny.sound

import com.github.minigdx.tiny.lua.Note
import com.github.minigdx.tiny.sound.SoundManager.Companion.SAMPLE_RATE
import kotlin.test.Test
import kotlin.test.assertEquals
Expand All @@ -10,7 +11,7 @@ class SongTest {

@Test
fun getPosition() {
val pattern = Pattern2(1, listOf(Sine2(0f, null, null)))
val pattern = Pattern2(1, listOf(Sine2(Note.C0, null, null, 1f)))
val track = Track(mapOf(1 to pattern), listOf(pattern, pattern, pattern), 1f, null, null)

val position = track.getPosition(0)
Expand All @@ -23,7 +24,7 @@ class SongTest {

@Test
fun getPositionOutOfTrack() {
val pattern = Pattern2(1, listOf(Sine2(0f, null, null)))
val pattern = Pattern2(1, listOf(Sine2(Note.C0, null, null, 1f)))
val track = Track(mapOf(1 to pattern), listOf(pattern, pattern, pattern), 1f, null, null)

val position = track.getPosition(Int.MAX_VALUE)
Expand All @@ -32,7 +33,7 @@ class SongTest {

@Test
fun getPositionInSecondPattern() {
val pattern = Pattern2(1, listOf(Sine2(0f, null, null), Sine2(0f, null, null)))
val pattern = Pattern2(1, listOf(Sine2(Note.C0, null, null, 1f), Sine2(Note.C0, null, null, 1f)))
val track = Track(mapOf(1 to pattern), listOf(pattern, pattern, pattern), 1f, null, null)

// 1 beats on the seconds pattern.
Expand Down
3 changes: 0 additions & 3 deletions tiny-engine/src/jvmMain/kotlin/com/DeleteMe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import com.github.minigdx.tiny.lua.SfxLib
import com.github.minigdx.tiny.platform.glfw.JavaMidiSoundManager

fun main() {
val sampleRate = 44100f // Fréquence d'échantillonnage en Hz
val duration = 0.2 // Durée en secondes

val score = """tiny-sfx 80 255
|02 00 00 00 00 00 01 01 00 FF 01
|011FFF 011FFF 011FFF 011FFF 011FFF 011FFF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ class JavaMidiSoundManager : SoundManager() {

while (isActive) {
val nextBuffer = bufferQueue.take()
if (notesLine.isActive) {
notesLine.close()
notesLine.open()
notesLine.start()
}
if (isActive) {
notesLine.write(nextBuffer, 0, nextBuffer.size)
Thread { notesLine.write(nextBuffer, 0, nextBuffer.size) }.start()
}
}
notesLine.close()
Expand Down

0 comments on commit e332066

Please sign in to comment.