{"id":19241592,"url":"https://github.com/cwbudde/websofa","last_synced_at":"2025-09-07T15:35:15.769Z","repository":{"id":22691148,"uuid":"97055453","full_name":"CWBudde/WebSofa","owner":"CWBudde","description":"JavaScript port of PasSofa","archived":false,"fork":false,"pushed_at":"2022-05-25T12:43:43.000Z","size":6316,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T11:53:44.720Z","etag":null,"topics":["acoustics","hdf5-format","hrtf","javascript","library","sofa","spatial-audio"],"latest_commit_sha":null,"homepage":null,"language":"Pascal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CWBudde.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-12T22:00:27.000Z","updated_at":"2023-07-18T18:34:13.000Z","dependencies_parsed_at":"2022-08-28T06:23:19.176Z","dependency_job_id":null,"html_url":"https://github.com/CWBudde/WebSofa","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CWBudde%2FWebSofa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CWBudde%2FWebSofa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CWBudde%2FWebSofa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CWBudde%2FWebSofa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CWBudde","download_url":"https://codeload.github.com/CWBudde/WebSofa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250032147,"owners_count":21363780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["acoustics","hdf5-format","hrtf","javascript","library","sofa","spatial-audio"],"created_at":"2024-11-09T17:11:56.897Z","updated_at":"2025-04-21T09:32:28.042Z","avatar_url":"https://github.com/CWBudde.png","language":"Pascal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebSofa\nWebSofa is a JavaScript library for reading SOFA files. It is written in Object Pascal, but easily transcompiles to JavaScript using the [Hope](https://github.com/Walibeiro/Hope) command line compiler.\n\nWebSofa makes use of the [WebHdf](https://github.com/CWBudde/WebHdf) code to read Hdf files.\n\n## Online Demo\nSince the compiled JavaScript code can run easily in any browser, a simple demo is available [here](https://rawgit.com/CWBudde/WebSofa/master/Demo/www/index.html)\n\n## Usage\nWhile the source of this code is aimed to transcompile from Object Pascal to monolithic JavaScript code including everything, a dedicated library 'Sofa.js' is available as well. With this it's easy to add SOFA to any website or web-app. It should include everything to load and handle SOFA files.\n\nFor now, the API is kept very simple and C-like. In the future a more JavaScript like API will be added.\n\nIn order to load a sofa file you must first load the file into a UInt8Array buffer. Typically this can be achieved by an [Xml HTTP Request](https://en.wikipedia.org/wiki/XMLHttpRequest) or with the help of a [FileReader](https://www.w3.org/TR/file-upload/).\n\nOnce you have the content of a file as an array buffer you can load it with\n\n    var handle = sofaLoadFile(Buffer);\n\nThis will return a handle to a sofa file. The handle (which is in fact a complex JavaScript object) you can access all the other features from the specification. For example to get the title of a sof file call:\n\n    var title = sofaGetAttribute(handle, 'Title');\n\nHowever, the more interesting information are the HRTF filters. To obtain a filter call\n\n    var filter = sofaGetFilterCartesian(handle, x, y, z);\n    \nin cartesian coordinates or if you prefer spherical coordinates call\n\n    var filter = sofaGetFilterSpherical(handle, phi, theta, radius);\n\nBoth functions will return the closest HRTF filter to the given position in a JavaScript object. This object contains the following values:\n\n    {\n      SampleRate //Number\n      Left, Right // Float64Array\n      LeftDelay, RightDelay // Number\n    }\n\nWhile these are the basic information to run a spacial audio renderer, you might need to do a few more steps before. In case of a typical [Web Audio API](https://www.w3.org/TR/webaudio/) implementation you would need at least to convert the 64-bit floating point data to 32-bit. This step is pretty straight forward:\n\n     var Left32 = new Float32Array(filter.Left);\n     var Right32 = new Float32Array(filter.Right);\n\nNext it's likely that you need to match the samplerate. This can be done quick and dirty by using the offline context of the Web Audio API like:\n\n      if (AudioContext.sampleRate!=filter.SampleRate) {\n        var OfflineAudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext;\n        OfflineAudioContext = new OfflineAudioContext(2, Left32.length, AudioContext.sampleRate);\n        ...\n\nThe resulting buffer can then be used in a convolver node (from the Web Audio API).\n\n## Roadmap\nAt the moment no HRTF interpolation is performed nor does the library contain any audio processing code (such as a sophisticated  resampler to match the sample rate). Finally, the performance hasn't yet been optimized so far. All this is on my list for future updates, but given the fact that this is a hobby project there is no time schedule for this.\n\n## Disclaimer\nThe code slightly relates to [libmysofa](https://github.com/hoene/libmysofa). However, it is written mostly from scratch. Similarities might occur from the fact that both are meant for the same purpose and using the same underlying specification.\n\nHowever, thanks to [Christian Hoene](mailto:christian.hoene@symonics.com) who wrote and published the libmysofa library. Without his reverse engineering of some (rather undocumented) parts of the specification it wouldn't have been possible to create this code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcwbudde%2Fwebsofa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcwbudde%2Fwebsofa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcwbudde%2Fwebsofa/lists"}