Skip to content

Commit

Permalink
Merge pull request #106 from alnitak/capture
Browse files Browse the repository at this point in the history
experimental capture feature removed
  • Loading branch information
alnitak committed Jul 22, 2024
2 parents a5a34ac + fd9d2e6 commit 4cd6e0b
Show file tree
Hide file tree
Showing 36 changed files with 29 additions and 1,641 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- added voice groups.
- it's now possible to set filters not only globally, but also to single audio sources.
- fade and oscillate filter parameters.
- experimental capture feature removed.

### 2.0.2 (23 May 2024)
- Fixed wrong exception raised by `setVolume()` when a handle is no more valid.
Expand Down
2 changes: 0 additions & 2 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ list(APPEND PLUGIN_SOURCES
"${SRC_DIR}/bindings.cpp"
"${SRC_DIR}/player.cpp"
"${SRC_DIR}/analyzer.cpp"
"${SRC_DIR}/bindings_capture.cpp"
"${SRC_DIR}/capture.cpp"
"${SRC_DIR}/synth/basic_wave.cpp"
"${SRC_DIR}/filters/filters.cpp"
${TARGET_SOURCES}
Expand Down
135 changes: 0 additions & 135 deletions example/lib/controls.dart

This file was deleted.

1 change: 0 additions & 1 deletion example/lib/main_wav_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class _MyHomePageState extends State<MyHomePage> {

Future<void> stop() async {
SoLoud.instance.deinit();
SoLoudCapture.instance.stopCapture();
sounds.clear();
}

Expand Down
141 changes: 0 additions & 141 deletions example/lib/page_hello_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter_soloud/flutter_soloud.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -77,34 +76,6 @@ class _PageHelloFlutterSoLoudState extends State<PageHelloFlutterSoLoud> {
textAlign: TextAlign.center,
),
),
Column(
children: [
/// start/stop the capture
ElevatedButton(
onPressed: () async {
if (SoLoudCapture.instance.isCaptureInited) {
SoLoudCapture.instance.stopCapture();
if (context.mounted) setState(() {});
} else {
final a = SoLoudCapture.instance.init();
final b = SoLoudCapture.instance.startCapture();
if (context.mounted &&
a == CaptureErrors.captureNoError &&
b == CaptureErrors.captureNoError) {
setState(() {});
}
}
},
child: const Text('start/stop mic'),
),
const SizedBox(height: 16),
if (SoLoudCapture.instance.isCaptureInited)
const MicAudioWidget(
width: 100,
height: 100,
),
],
),
],
),
),
Expand Down Expand Up @@ -165,115 +136,3 @@ class _PageHelloFlutterSoLoudState extends State<PageHelloFlutterSoLoud> {
await SoLoud.instance.play(currentSound!);
}
}

/// widget that uses a ticker to read and provide audio
/// data to [MicAudioPainter]
///
class MicAudioWidget extends StatefulWidget {
const MicAudioWidget({
required this.width,
required this.height,
super.key,
});
final double width;
final double height;

@override
State<MicAudioWidget> createState() => _MicAudioWidgetState();
}

class _MicAudioWidgetState extends State<MicAudioWidget>
with SingleTickerProviderStateMixin {
Ticker? ticker;
final audioData = AudioData(
GetSamplesFrom.microphone,
GetSamplesKind.wave,
);

@override
void initState() {
super.initState();
ticker = createTicker((Duration elapsed) {
if (context.mounted) {
try {
audioData.updateSamples();
setState(() {});
} on Exception catch (e) {
debugPrint('$e');
}
}
});
ticker?.start();
}

@override
void dispose() {
ticker?.stop();
audioData.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return RepaintBoundary(
child: CustomPaint(
size: Size(widget.width, widget.height),
painter: MicAudioPainter(audioData: audioData),
),
);
}
}

/// Custom painter to draw the wave in a circle
///
class MicAudioPainter extends CustomPainter {
const MicAudioPainter({
required this.audioData,
});
final AudioData audioData;

@override
void paint(Canvas canvas, Size size) {
final path = Path();

/// draw background circle
canvas.drawCircle(
Offset(size.width / 2, size.height / 2),
size.height / 2,
Paint()
..color = Colors.blue
..style = PaintingStyle.fill,
);

/// simplify the first row of 256 FFT data to
final data = Float64List(32);
for (var n = 0; n < 32; n++) {
var f = 0.0;
for (var i = 0; i < 8; i++) {
f += audioData.getWave(SampleWave(n * 8 + i));
}
data[n] = f / 8;
}

final stepX = size.width / 32;
path.moveTo(0, (size.height / 2) + data[0] * size.height);
for (var n = 1; n < 32; n++) {
path.lineTo(
n * stepX,
(size.height / 2) + data[n] * size.height,
);
}
canvas.drawPath(
path,
Paint()
..color = Colors.white
..style = PaintingStyle.stroke
..strokeWidth = 4,
);
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
Loading

0 comments on commit 4cd6e0b

Please sign in to comment.