Origin Scripting Language
  • Basics
    • Syntax
    • Types
    • The Execution Loop
    • Defining Variables
      • Clone Objects (=)
      • References To Objects/Variables (@=)
    • Assignment Operators
    • Local Scoping
    • Typed Variables
  • Operators
    • Mathematical Usage
      • Addition Operator (+)
      • Subtraction Operator (-)
      • Divide Operator (/)
      • Multiply Operator (*)
      • To The Power Of (^)
      • Modulo Operator (%)
    • Text Usage
    • String Concatenation Operator (+)
    • Array Operations
    • Comparative Operators
    • Logical Operators
    • Bitwise operators
    • Pipe Operator (|>)
    • Nullish Coalescing Operator (??)
  • Program Flow
    • If Statements
      • if truthy (
      • ) else if truthy (
      • ) else (
      • )
    • Switch Case
    • Iteration
    • While And Until
    • Dynamic OSL Execution
  • Arrays And Objects
    • Making Arrays Or Objects
    • Modifying An Array
    • Clone Objects And References
    • Object Operations
    • Object Property Shorthand
  • Environment
    • The Window System
    • Mouse Cursor
    • Camera
    • Sound System
    • Input Simulation
    • Running Other Languages
    • Notifications
    • Send Data Between Windows
    • Interfacing With Rightclick
    • Permissions
    • Files
      • What is a file? (in ofsf)
      • Creating Directories
      • open("file_path")
      • fileGet(int)
      • listFiles()
  • Storage
    • Save DB
    • Local DB
  • Custom Syntax
    • Commands
    • Methods
    • Functions
    • Inline
    • Lambda
    • Spread Operator
    • Typed Parameters
    • Classes
    • Promises
  • External
    • Make An Iframe App
  • Commands
    • Debugging
      • log "hello world"
      • warn "you should change this"
      • error "something went wrong"
      • void expression
    • Rendering
      • Basics
        • Color Commands
        • Color Picker
        • Modifiers
      • Draw Cursor
        • goto x y
        • set_x x
        • set_y y
        • change_x x
        • change_y y
        • change x y
        • loc a b c d
      • Elements
        • Canvas
        • Rectangle
        • Triangle
        • Icon
        • Text
        • Image
        • Input
        • Pen
        • Hitbox
        • Bar
        • Slider
      • ICN (Icon System)
        • Drawing Commands
        • Dynamic Icons
      • Clipping And Scrolling (frames)
      • 3D Rendering
  • Functions
    • Math
      • Math()
      • random(low,high)
      • min(num1,num2)
      • max(num1,num2)
      • lcm(num1,num2)
      • gcd(num1,num2)
      • sum(num1,..)
      • average(num1,..)
      • dist(x1,y1,x2,y2)
      • degtorad(angle)
      • radtodeg(angle)
      • noise(x, y, z)
      • octaveNoise(x, y, z, octaves, persistence)
    • Types
      • typeof(value)
      • symbol(name)
    • Encoding
      • encodeURIComponent(string)
      • decodeURIComponent(string)
      • btoa/atob(string)
    • function()
    • formatFileSize(bytes)
    • getGamepads()
    • import(path)
    • ouidNew()
    • parseFilePath(path)
  • Global Variables
    • Overview
    • System Information
    • User Information
    • Date and Time
    • Input State
    • Display and UI
    • Network
    • File System
  • Methods
    • Strings
      • .padStart(num,val)
      • .padEnd(num,val)
      • .startsWith(val)
      • .endsWith(val)
      • .wrapText(characters)
      • .trimText(characters)
      • .split(characters)
      • .count(val)
      • .replace(old,new)
      • .replaceFirst(old,new)
      • .oslTokenise()
      • .strip()
      • .toOrdArray()
      • .match(pattern)
      • Encoding
        • .encodeBin()
        • .decodeBin()
        • .encodeHex()
        • .decodeHex()
        • .encodeUTF16()
        • .decodeUTF16()
        • .encrypt(password)
        • .decrypt(password)
        • .ord()
        • .chr()
      • Hashing
        • .hashMD5()
        • .hashSHA1()
        • .hashSHA256()
        • .hashSHA512()
      • Case
        • .toLower()
        • .toUpper()
        • .toMixed()
        • .toTitle()
    • Keyboard
      • .isKeyDown()
      • .onKeyDown()
    • Utilities
      • .len
      • .not
      • .ask()
      • .reverse()
      • .first()
      • .last()
      • .append(val)
      • .prepend(val)
      • .insert(location,val)
      • .delete(location)
      • .concat(val)
      • .trim(idx1,idx2)
      • .left(num)
      • .right(num)
      • .contains(val)
      • .index(val)
    • Maths
      • .abs()
      • .invabs()
      • .log()
      • .ln()
      • .isPrime()
      • .sqrt()
      • .sign()
      • .chance()
      • .clamp(low,high)
      • .toBase(base)
      • Rounding
        • .round(places)
        • .ceiling()
        • .floor()
      • Trigonometry
        • .sin
        • .cos
        • .tan
        • .asin()
        • .acos()
        • .atan()
        • .radSin()
        • .radCos()
    • Iframes
      • .iframeNew()
      • .iframeGoto()
      • .iframeResize()
      • .iframeRedirect()
      • .iframeShow()
      • .iframeHide()
      • .iframeClose()
    • JSON
      • Arrays
        • .pop()
        • .shift()
        • .randomOf()
        • .sort(direction)
        • .sortBy(key,direction)
        • .swap(idx1,idx2)
        • .fill(value)
        • .join(characters)
        • .map(callback)
        • .filter(callback)
        • .some(callback)
        • .every(callback)
      • Objects
        • .getKeys(keys)
        • .getValues()
      • .JsonStringify()
      • .JsonParse()
      • .JsonFormat()
      • .JsonClean()
    • Types
      • .getType()
      • .isType(type)
      • .toNum()
      • .toBool()
      • .toStr()
    • Functions
      • .bind(context)
    • Networking
      • .httpGet()
      • .http(method,data,headers)
      • .getAsync()
      • .roturConnect()
      • .roturSend(msg,target)
      • Websockets
        • .newWebsocket()
        • .wsSend(msg)
        • .wsClose()
        • .wsOpen()
        • .wsHasnew()
        • .wsGetnext()
        • .wsGetcount()
    • Timestamp
      • .timestamp("convert-date")
      • .timestamp("component")
Powered by GitBook
On this page
  • Basic Commands
  • Loading Sounds
  • Playback Control
  • Sound Properties
  • Sound Information Methods
  • Multiple Sound Support
  • Example Usage
  • Basic Sound Player
  • Advanced Sound Control
  • Sound Progress Tracker
  • Important Notes

Was this helpful?

Edit on GitHub
  1. Environment

Sound System

OSL provides a comprehensive sound system for loading, playing, and manipulating audio in your applications.

Note: Sound handling requires OriginOS version 4.6.4 or later.

Basic Commands

Loading Sounds

Load a sound into RAM from a URL or data URI:

sound "url" "load" "name"

Playback Control

// Play from beginning
sound "url"/"name" "play"

// Pause playback
sound "url"/"name" "pause"

// Resume playback
sound "url"/"name" "unpause"

// Start at specific time
sound "url"/"name" "start" time

// Remove sound from memory
sound "url"/"name" "clear"

Sound Properties

// Adjust volume (0-1)
sound "url"/"name" "volume" int

// Change playback speed (default: 1)
sound "url"/"name" "speed" int

Sound Information Methods

// Check if sound is loaded
"sound_name".soundinfo("loaded")    // Returns boolean

// Get sound duration
"sound_name".soundinfo("duration")  // Returns seconds

// Get current playback position
"sound_name".soundinfo("current_time")

// Get current volume
"sound_name".soundinfo("volume")

// Get current pitch
"sound_name".soundinfo("pitch")

// Check if sound is playing
"sound_name".soundinfo("playing")   // Returns boolean

Multiple Sound Support

You can pass multiple sounds in an array to apply commands to multiple sounds simultaneously:

// Pause multiple sounds
sound ["sound1", "sound2"] "pause"

// Adjust volume for multiple sounds
sound ["background", "effects"] "volume" 0.5

Example Usage

Basic Sound Player

// Load sound
sound_url = "https://example.com/music.mp3"
sound sound_url "load" "background_music"

// Play when loaded
if "background_music".soundinfo("loaded") (
    sound "background_music" "play"
)

Advanced Sound Control

// Load multiple sounds
sound "effect.wav" "load" "effect1"
sound "music.mp3" "load" "music"

mainloop:
    // Check if music is playing
    if "music".soundinfo("playing").not (
        // Start music if not playing
        sound "music" "play"
        sound "music" "volume" 0.7
    )
    
    // Play effect on spacebar
    if " ".isKeyDown() (
        sound "effect1" "play"
    )

Sound Progress Tracker

sound "song.mp3" "load" "current_song"

mainloop:
    if "current_song".soundinfo("loaded") (
        current = "current_song".soundinfo("current_time")
        total = "current_song".soundinfo("duration")
        progress = current / total
        
        // Display progress bar
        bar 200 20 5 progress
    )

Important Notes

  • Always check if sounds are loaded before playing

  • Sound URLs can be external or data URIs

  • Volume values range from 0 to 1

  • Default playback speed is 1

  • Multiple sounds can be controlled simultaneously using arrays

  • Sound names must be unique when loading

  • Memory management is important - clear unused sounds

  • Sound availability depends on browser and system support

PreviousCameraNextInput Simulation

Last updated 3 months ago

Was this helpful?