[EOS] set audio volume of left and right channel independently

Post all technical issues and questions here. We'll gladly help you wherever we can.
Post Reply
gagaga
Explorer
Explorer
Posts: 15
Joined: Mon Sep 13, 2021 6:55 pm

[EOS] set audio volume of left and right channel independently

Post by gagaga »

Hi,

For a estim webtease I'm trying to adjust the volume of the left and right channel independently.
Do you know how?

Since EOS uses Howler for audio playback I was trying to use the panning feature of howler.spatial (see https://github.com/goldfire/howler.js#stereopan-id), but no luck so far... I could not even access the this.sound variable in the AudioClip class from an EOS page. Here is the code of AudioClip.js for the refernce:

Code: Select all

import { Howl } from 'howler'
import _debug from 'debug'
const debug = _debug('eos:audio:AudioClip')

export default class AudioClip {
  constructor({ url, loops, volume, onDestroy }) {
    this.url = url
    this.loops = loops
    this.loopsRemaining = loops - 1
    this.onDestroy = onDestroy
    this.isDestroyed = false
    this.sound = new Howl({
      src: [url],
      format: ['mp3'],
      volume,
      onend: this.handleEnded.bind(this),
      html5: false
    })
  }

  play() {
    if (this.isDestroyed) return
    debug('playing sound %s', this.url)
    this.sound.play()
  }

  pause() {
    if (this.isDestroyed) return
    this.sound.pause()
  }

  stop() {
    if (this.isDestroyed) return
    debug('stopping sound %s', this.url)
    this.sound.stop()
  }

  seek(time) {
    if (this.isDestroyed) return
    this.sound.seek(time)
  }

  setVolume(volume) {
    if (this.isDestroyed) return
    this.sound.volume(volume)
  }

  destroy() {
    if (this.isDestroyed) return
    this.stop()
    this.isDestroyed = true
    if (typeof this.onDestroy === 'function') {
      this.onDestroy()
    }
  }

  handleEnded() {
    if (this.isDestroyed) return
    if (this.loopsRemaining > 0) {
      this.loopsRemaining--
      this.sound.play()
    }
  }
}
Maybe some expert can provide a small sample script with panning in EOS?

Thanks for your feedback!
verynicekojak
Explorer
Explorer
Posts: 88
Joined: Fri Aug 19, 2022 10:05 pm

Re: [EOS] set audio volume of left and right channel independently

Post by verynicekojak »

I think that EOS is very restricted so you don't have access to anything like that.
You probably need to have two different audio files (left and right) and play them at the same time.
gagaga
Explorer
Explorer
Posts: 15
Joined: Mon Sep 13, 2021 6:55 pm

Re: [EOS] set audio volume of left and right channel independently

Post by gagaga »

verynicekojak wrote: Wed Oct 11, 2023 11:32 pm I think that EOS is very restricted so you don't have access to anything like that.
You probably need to have two different audio files (left and right) and play them at the same time.
That's a very easy solution and works great!
:thankyou:
Post Reply

Who is online

Users browsing this forum: No registered users and 66 guests