Skip to content

Commit

Permalink
Support to chaining multiple data sources gapless
Browse files Browse the repository at this point in the history
  • Loading branch information
fgnm committed Dec 8, 2023
1 parent 004490c commit 6d42339
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- Update libGDX to 1.12.1
- Support MASound end callback
- Allow to disable low latency mode
- Support chaining multiple data sources gapless
- Fix iOS native crash when file doesn't exists
- Workaround AAudio issues, limit this backend to Android >= 12

[0.3]
- Full MiniAudio engine customization
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/games/rednblack/miniaudio/MASound.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
public class MASound extends MANode {

private MADataSource dataSource;

MASound(MiniAudio miniAudio) {
super(miniAudio);
}
Expand All @@ -21,6 +23,12 @@ void setAddress(long address) {
throw new MiniAudioException("Error while loading Sound", (int) address);
}
this.address = address;
dataSource = new MADataSource(miniAudio.getSoundDataSource(this.address), miniAudio) {
@Override
public void dispose() {

}
};
}

/**
Expand Down Expand Up @@ -321,6 +329,15 @@ public void dispose() {
miniAudio.disposeSound(address);
}

/**
* Get the data source attached to this sound object
*
* @return An empty {@link MADataSource} to store data source address
*/
public MADataSource getDataSource() {
return dataSource;
}

@Override
public void attachToThisNode(MANode previousNode, int outputBus) {
throw new RuntimeException("Sounds doesn't have input bus");
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/games/rednblack/miniaudio/MiniAudio.java
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,26 @@ public void disposeSound(long soundAddress) {
ma_free(sound, NULL);
*/

public long getSoundDataSource(long soundAddress) {
return jniGetSoundDataSource(soundAddress);
}

private native long jniGetSoundDataSource(long soundAddress);/*
ma_sound* sound = (ma_sound*) soundAddress;
return (jlong) sound->pDataSource;
*/

public void chainDataSources(MADataSource dataSource, MADataSource nextDataSource) {
int result = jniChainDataSources(dataSource.address, nextDataSource.address);
if (result != MAResult.MA_SUCCESS) {
throw new MiniAudioException("Error while chaining data sources", result);
}
}

private native int jniChainDataSources(long dataSource, long nextDataSource);/*
return ma_data_source_set_next((ma_data_source*) dataSource, (ma_data_source*) nextDataSource);
*/

/**
* Play or resume sound.
*
Expand Down

0 comments on commit 6d42339

Please sign in to comment.