Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LoadMode.disk on Web #173

Merged
merged 14 commits into from
Feb 2, 2025
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Flutter debug",
"type": "dart",
"request": "launch",
"program": "lib/main.dart",
"program": "lib/audio_data/audio_data.dart",
"flutterMode": "debug",
"cwd": "${workspaceFolder}/example"
},
Expand Down
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"label": "compile linux debug",
"command": "cd ${workspaceFolder}/example; flutter build linux -t lib/main.dart --debug",
"command": "cd ${workspaceFolder}/example; flutter build linux -t lib/test.dart --debug",
"type": "shell"
},
{
Expand All @@ -29,7 +29,7 @@
},
{
"label": "compile web wasm release",
"command": "cd ${workspaceFolder}/example; flutter run -d chrome --web-renderer canvaskit --web-browser-flag '--disable-web-security' -t lib/buffer_stream/websocket.dart --release",
"command": "cd ${workspaceFolder}/example; flutter run -d chrome --wasm --web-browser-flag '--disable-web-security' -t lib/audio_data/audio_data.dart --release",
"type": "shell"
},
{
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

### 3.0.0-pre.0 ()
- fix: clicks and pops when changing waveform frequency #156
- fix: clicks and pops when changing waveform frequency #156.
- added `Limiter` and `Compressor` filters (see `example/lib/filters/`).
- added BufferStream #148. Now it's possible to add audio data and listen to them. It provides a customizable buffering length which automatycally pauses the playing handle if there is not enough data, for example when receiving audio data from the web. It also provides a callback that allows you to know when the buffering is started and stopped. The audio data can of of the following formats:
- `s8` signed 8 bit
- `s16le` signed 16 bit little endian
Expand All @@ -9,6 +10,9 @@
- `opus` Opus codec compressed audio with Ogg container. Usefull for streaming from the Web (ie using OpenAI APIs).
- fixed Web Worker initialization non fatal error that could occur on Web.
- fixed sound distortion using single pitchShift filter and changing relative play speed #154.
- fixed the use of `LoadMode.disk` on the Web platform which in some cases caused the `allInstancesFinished` event to not be emitted.
- improved performance on Web, MacOS and iOS.
- get wave and FFT sample is now simpler and faster.
- To avoid future incompatibilities when using other WASM compiled plugins, it is now necessary to add a new script to `index.html`:
```
<script src="assets/packages/flutter_soloud/web/libflutter_soloud_plugin.js" defer></script>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ For more simple examples, check out the [example/project](https://github.com/aln
| Example | Description |
|-----------------|-------------|
|*lib/main.dart* |Very simple example where to start from. |
|*lib/audio_data/audio_data.dart* |Simple exmple to show how to use the `AudioData` to visualize audio. |
|*lib/audio_data/audio_data.dart* |Simple example to show how to use the `AudioData` to visualize audio. |
|*lib/buffer_stream/generate.dart* |Example of how to generate PCM audio inside an `Isolate` and play them. |
|*lib/buffer_stream/websocket.dart* |Shows how to use BufferStream with a websocket to get PCM and Opus audio data. |
|*lib/filters/compressor.dart* |Shows the use of the compressor filter. |
Expand Down
119 changes: 0 additions & 119 deletions example/example.md

This file was deleted.

4 changes: 3 additions & 1 deletion example/lib/audio_data/audio_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class _HelloFlutterSoLoudState extends State<HelloFlutterSoLoud> {
@override
void initState() {
super.initState();
SoLoud.instance.loadAsset('assets/audio/8_bit_mentality.mp3').then((value) {
SoLoud.instance
.loadAsset('assets/audio/8_bit_mentality.mp3', mode: LoadMode.disk)
.then((value) {
currentSound = value;
SoLoud.instance.play(currentSound!, looping: true, volume: 0.5);
if (context.mounted) setState(() {});
Expand Down
18 changes: 9 additions & 9 deletions example/lib/audio_data/data_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ class AudioDataWidgetState extends State<AudioDataWidget>

/// Set [AudioData] to use a `linear` data kind. This is the way to get both
/// wave and FFT data.
final AudioData audioData = AudioData(
GetSamplesKind.linear,
);
final AudioData audioData = AudioData(GetSamplesKind.linear);

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -87,14 +86,15 @@ class WavePainter extends CustomPainter {
..strokeWidth = barWidth * 0.8
..color = Colors.yellowAccent;

final samples = audioData.getAudioData();

double waveHeight;
double fftHeight;

for (var i = 0; i < 256; i++) {
late final double waveHeight;
late final double fftHeight;
try {
final double waveData;
final double fftData;
waveData = audioData.getLinearWave(SampleLinear(i));
fftData = audioData.getLinearFft(SampleLinear(i));
final fftData = samples[i];
final waveData = samples[i + 256];
waveHeight = size.height * waveData * 0.5;
fftHeight = size.height * fftData / 2;
} on Exception {
Expand Down
3 changes: 2 additions & 1 deletion example/lib/filters/pitchshift.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import 'package:logging/logging.dart';

/// Use the filter globally or attached to the sound. Filters for single sounds
/// are not supported in the Web platform.
const bool useGlobalFilter = true;
const bool useGlobalFilter = false;

void main() async {
// The `flutter_soloud` package logs everything
Expand Down Expand Up @@ -136,6 +136,7 @@ class _PitchShiftState extends State<PitchShift> {
Text('time stretching: ${ts.toStringAsFixed(2)}'),
Expanded(
child: Slider.adaptive(
min: 0.35,
max: 5,
value: ts,
onChanged: (value) {
Expand Down
6 changes: 4 additions & 2 deletions example/tests/tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ Future<StringBuffer> testAllInstancesFinished() async {

final explosion =
await SoLoud.instance.loadAsset('assets/audio/explosion.mp3');
final song =
await SoLoud.instance.loadAsset('assets/audio/8_bit_mentality.mp3');
final song = await SoLoud.instance.loadAsset(
'assets/audio/8_bit_mentality.mp3',
mode: LoadMode.disk,
);

// Set up unloading.
var explosionDisposed = false;
Expand Down
1 change: 0 additions & 1 deletion lib/flutter_soloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ library;

export 'src/audio_source.dart';
export 'src/bindings/audio_data.dart';
export 'src/bindings/audio_data_extensions.dart';
export 'src/enums.dart' hide PlayerErrors, PlayerStateNotification;
export 'src/exceptions/exceptions.dart';
export 'src/filter_params.dart';
Expand Down
Loading