Skip to content

fix: Cannot fade 3d source before setting listener position #168

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

Closed
chrisnorman7 opened this issue Jan 13, 2025 · 2 comments
Closed

fix: Cannot fade 3d source before setting listener position #168

chrisnorman7 opened this issue Jan 13, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@chrisnorman7
Copy link

Description

If you call play3d with a volume of 0.0 and then fade the resulting sound, no audio will be heard until a call is made to set3dListenerPosition.

Steps To Reproduce

  1. Enter the following cod.
  2. Run the program.
  3. Click the "Play sound" button.
  4. Hear nothing.
  5. Click the "Set listener position" button.
  6. Hear sound.
import 'package:flutter/material.dart';
import 'package:flutter_soloud/flutter_soloud.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // TRY THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  /// Create an instance.
  const MyHomePage({
    super.key,
  });

  /// Create state for this widget.
  @override
  MyHomePageState createState() => MyHomePageState();
}

/// State for [MyHomePage].
class MyHomePageState extends State<MyHomePage> {
  /// Build a widget.
  @override
  Widget build(BuildContext context) {
    final soLoud = SoLoud.instance;
    return Scaffold(
      appBar: AppBar(
        title: Text('Example'),
      ),
      body: Column(
        children: [
          TextButton(
            onPressed: () async {
              await soLoud.init();
              final source = await soLoud.loadUrl(
                'https://file-examples.com/storage/fe602ed48f677b2319947f8/2017/11/file_example_MP3_700KB.mp3',
              );
              final handle = await soLoud.play3d(
                source,
                0.0,
                0.0,
                0.0,
                looping: true,
                volume: 0.0,
              );
              soLoud.fadeVolume(handle, 1.0, Duration(seconds: 3));
            },
            autofocus: true,
            child: Text('Play sound'),
          ),
          TextButton(
            onPressed: () => soLoud.set3dListenerPosition(0.0, 0.0, 0.0),
            child: Text('Set listener position'),
          )
        ],
      ),
    );
  }
}

Expected Behavior

You should hear the sound slowly fading up.

Additional Context

There may be a better way to fade sounds up, but I don't know about it.

@chrisnorman7 chrisnorman7 added the bug Something isn't working label Jan 13, 2025
@alnitak
Copy link
Owner

alnitak commented Jan 13, 2025

Hi @chrisnorman7,

this seems a bug in the C++ SoLoud lib. When using 3D sound, the doc says:

By default, if a sound is inaudible, it's paused, and will resume when it becomes audible again.

That setinaudiblebehavior function is already on the main branch, but not yet on pub.dev. This function works when you already have a sound handle, I need to add the counterpart for the AudioSource that should prevent this issue.

A sound becomes inaudible when the volume goes below 0.01 and maybe something wrong happens here when using 0.

To temporarily solve this issue, please play the sound starting with a volume of 0.01.

I will try to look further and I'll update you.

@chrisnorman7
Copy link
Author

chrisnorman7 commented Jan 13, 2025 via email

@alnitak alnitak closed this as completed May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants