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: clicks and pops when changing waveform frequency #156 #158

Merged
merged 9 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/buffer_stream/websocket.dart",
"program": "lib/waveform/waveform.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/buffer_stream/websocket.dart --debug",
"command": "cd ${workspaceFolder}/example; flutter build linux -t lib/waveform/waveform.dart --debug",
"type": "shell"
},
{
Expand All @@ -29,7 +29,7 @@
},
{
"label": "compile web debug",
"command": "cd ${workspaceFolder}/example; flutter run -d chrome --web-renderer canvaskit --web-browser-flag '--disable-web-security' -t lib/main.dart --release",
"command": "cd ${workspaceFolder}/example; flutter run -d chrome --web-renderer canvaskit --web-browser-flag '--disable-web-security' -t lib/waveform/waveform.dart --release",
"type": "shell"
},
{
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 2.1.8 ()
- fix: clicks and pops when changing waveform frequency #156
- added BufferStream #148. Now it's possible to add audio data and listen to them. It provides a customizable buffering length which automatycally pause the playing handle for example when receiving audio data from the web.

### 2.1.7 (29 Oct 2024)
- added `listPlaybackDevices` to get all the OS output devices available.
- added `deviceId` parameter to the `init()` method. You can choose which device is delegated to output the audio.
Expand Down
238 changes: 122 additions & 116 deletions example/lib/waveform/waveform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MyApp extends StatelessWidget {
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
home: const MyHomePage(title: 'Flutter SoLoud waveform demo'),
);
}
}
Expand Down Expand Up @@ -122,126 +122,132 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Padding(
padding: const EdgeInsets.all(16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('SuperWave : $superWave'),
Switch(
value: superWave,
onChanged: (value) {
setState(() {
superWave = value;
if (currentSound != null && isPlaying) {
SoLoud.instance
.setWaveformSuperWave(currentSound!, value);
}
});
},
),
const SizedBox(height: 20),
Text('Scale : ${scale.toStringAsFixed(2)}'),
Slider(
value: scale,
max: 4,
onChanged: !superWave
? null
: (value) {
setState(() {
scale = value;
if (currentSound != null && isPlaying) {
SoLoud.instance
.setWaveformScale(currentSound!, value);
}
});
},
label: 'Scale: ${scale.toStringAsFixed(2)}',
activeColor: Colors.green,
inactiveColor: Colors.green[100],
),
const SizedBox(height: 20),
Text('Detune : ${detune.toStringAsFixed(2)}'),
Slider(
value: detune,
max: 2,
onChanged: !superWave
? null
: (value) {
setState(() {
detune = value;
if (currentSound != null && isPlaying) {
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('SuperWave : $superWave'),
Switch(
value: superWave,
onChanged: (value) {
setState(() {
superWave = value;
if (currentSound != null && isPlaying) {
SoLoud.instance
.setWaveformSuperWave(currentSound!, value);
}
});
},
),
const SizedBox(height: 20),
Text('Scale : ${scale.toStringAsFixed(2)}'),
Slider(
value: scale,
max: 4,
onChanged: !superWave
? null
: (value) {
setState(() {
scale = value;
if (currentSound != null && isPlaying) {
SoLoud.instance
.setWaveformScale(currentSound!, value);
}
});
},
label: 'Scale: ${scale.toStringAsFixed(2)}',
activeColor: Colors.green,
inactiveColor: Colors.green[100],
),
const SizedBox(height: 20),
Text('Detune : ${detune.toStringAsFixed(2)}'),
Slider(
value: detune,
max: 2,
onChanged: !superWave
? null
: (value) {
setState(() {
detune = value;
if (currentSound != null && isPlaying) {
SoLoud.instance
.setWaveformDetune(currentSound!, value);
}
});
},
label: 'Detune: ${detune.toStringAsFixed(2)}',
activeColor: Colors.green,
),
const SizedBox(height: 20),
Text('Freequncy Hz: ${frequency.toInt()}'),
Slider(
value: frequency,
min: 20,
max: 2000,
onChanged: (value) {
setState(() {
frequency = value;

if (currentSound != null && isPlaying) {
SoLoud.instance.setWaveformFreq(currentSound!, value);
}
});
},
label: 'Frequency: ${frequency.toInt()} Hz',
activeColor: Colors.green,
inactiveColor: Colors.green[100],
),
const SizedBox(height: 50),

/// All waveform types.
Wrap(
runSpacing: 4,
spacing: 4,
alignment: WrapAlignment.center,
children: [
for (var i = 0; i < WaveForm.values.length; i++)
OutlinedButton(
onPressed: () {
setState(() {
waveForm = WaveForm.values[i];
SoLoud.instance
.setWaveformDetune(currentSound!, value);
}
});
},
label: 'Detune: ${detune.toStringAsFixed(2)}',
activeColor: Colors.green,
),
const SizedBox(height: 20),
Text('Freequncy Hz: ${frequency.toInt()}'),
Slider(
value: frequency,
min: 20,
max: 16000,
onChanged: (value) {
setState(() {
frequency = value;

if (currentSound != null && isPlaying) {
SoLoud.instance.setWaveformFreq(currentSound!, value);
}
});
},
label: 'Frequency: ${frequency.toInt()} Hz',
activeColor: Colors.green,
inactiveColor: Colors.green[100],
),
const SizedBox(height: 50),

/// All waveform types.
Wrap(
runSpacing: 4,
spacing: 4,
alignment: WrapAlignment.center,
children: [
for (var i = 0; i < WaveForm.values.length; i++)
OutlinedButton(
onPressed: () {
setState(() {
waveForm = WaveForm.values[i];
SoLoud.instance.setWaveform(currentSound!, waveForm);
});
},
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
waveForm == WaveForm.values[i]
? Colors.green
: Colors.transparent,
.setWaveform(currentSound!, waveForm);
});
},
style: ButtonStyle(
backgroundColor: WidgetStateProperty.all(
waveForm == WaveForm.values[i]
? Colors.green
: Colors.transparent,
),
),
child: Text(WaveForm.values[i].name),
),
child: Text(WaveForm.values[i].name),
),
],
),
const SizedBox(height: 50),
Align(
child: OutlinedButton(
onPressed: isPlaying ? null : () => play(frequency),
child: const Text('Play'),
],
),
),
const SizedBox(height: 20),
Align(
child: OutlinedButton(
onPressed: isPlaying ? stop : null,
child: const Text('Stop'),
const SizedBox(height: 50),
Align(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
OutlinedButton(
onPressed: isPlaying ? null : () => play(frequency),
child: const Text('Play'),
),
const SizedBox(width: 20),
OutlinedButton(
onPressed: isPlaying ? stop : null,
child: const Text('Stop'),
),
],
),
),
),
],
],
),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/linux/my_application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void my_application_activate(GApplication* application) {
gtk_window_set_title(window, "flutter_soloud_example");
}

gtk_window_set_default_size(window, 600, 580);
gtk_window_set_default_size(window, 600, 700);
gtk_widget_show(GTK_WIDGET(window));

g_autoptr(FlDartProject) project = fl_dart_project_new();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: >-
A low-level audio plugin for Flutter,
mainly meant for games and immersive apps.
Based on the SoLoud (C++) audio engine.
version: 2.1.7
version: 2.1.8
issue_tracker: https://github.com/alnitak/flutter_soloud/issues
homepage: https://github.com/alnitak/flutter_soloud
maintainer: Marco Bavagnoli (@lildeimos)
Expand Down
3 changes: 3 additions & 0 deletions src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ extern "C"
///
/// [hash] the unique sound hash of a waveform sound
/// [newFreq]

/// Thread to oscillate the frequency
std::thread waveformFreqThread;
FFI_PLUGIN_EXPORT void setWaveformFreq(unsigned int hash, float newFreq)
{
if (player.get() == nullptr || !player.get()->isInited())
Expand Down
Loading
Loading