Skip to content

fix: Audio degradation remains after pitch/time modification #313

@NikitaVasin

Description

@NikitaVasin

Description

When applying the pitchShiftFilter and changing timeStretch, the original sound becomes heavily distorted, resulting in a "robovoice"-like effect.
Even after resetting the value back to 1.0, the distortion does not go away and the sound remains degraded.

Steps To Reproduce

  1. Initialize SoLoud and load an audio file.
  2. Activate the pitchShiftFilter.
  3. Change the timeStretch value using a slider (e.g., from 1.0 to 0.5 or 2.0).

Expected Behavior

The quality should not deteriorate when changing the timeStretch.

Additional Context
• Flutter version: 3.35.2
• flutter_soloud version: 3.3.6
• Platform(s): Android/iOS

Code Sample

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SoLoud.instance.init();
  runApp(MaterialApp(home: const HomeScreen()));
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});
  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  double _speed = 1.0;
  AudioSource? audioSource;
  SoundHandle? soundHandle;

  @override
  void initState() {
    loadSound();
    super.initState();
  }

  Future<void> loadSound() async {
    final sound = await SoLoud.instance.loadAsset('assets/sound.mp3');
    sound.filters.pitchShiftFilter.activate();
    audioSource = sound;
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text('Speed: $_speed'),
          Slider(
            value: _speed,
            onChanged: (value) {
              _speed = value;
              setState(() {});
              if (audioSource != null && soundHandle != null) {
                audioSource!.filters.pitchShiftFilter.timeStretch(
                  soundHandle!,
                  value,
                );
              }
            },
            min: 0.2,
            max: 2,
          ),
          ElevatedButton(
            onPressed: () async {
              if (audioSource != null) {
                soundHandle = await SoLoud.instance.play(
                  audioSource!,
                  looping: true,
                );
              }
            },
            child: Text('Play'),
          ),
        ],
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions