Skip to content

ABI mode to API mode transition on cffi #338

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

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d63f379
ABI mode to API mode transition on cffi
ayghri Jun 8, 2022
f34b24b
correct soundfile.py
Jun 8, 2022
c0f2d91
Merge branch 'master' into git
Jun 8, 2022
e1d1410
printing platform when building
Jun 8, 2022
7bbc19d
Restored _SoundFileInfo
ayghri Jun 26, 2022
c1338ff
Added test workflow
Jul 30, 2022
73f0231
Update main.yml
Jul 31, 2022
314a125
Update .travis.yml
Jul 31, 2022
831aa8a
Tsting workflow for windows
Aug 4, 2022
67f4927
workflows more
Aug 4, 2022
18d9476
excludes some architectures
Aug 4, 2022
c519562
editting windows includes
Aug 4, 2022
fff4ca7
Create windows.yaml
Aug 4, 2022
7991101
Update windows.yaml
Aug 4, 2022
876ae02
Update windows.yaml
Aug 4, 2022
3f271cf
Update setup.py
Aug 4, 2022
afe60c5
Update windows.yaml
Aug 4, 2022
3790365
Update windows.yaml
Aug 4, 2022
1694bb8
Update setup.py
Aug 4, 2022
dee629f
Update setup.py
Aug 4, 2022
1dc09e6
Update setup.py
Aug 4, 2022
c9b937d
Update soundfile_build.py
Aug 4, 2022
0cb963f
Update windows.yaml
Aug 4, 2022
75090f3
Update soundfile_build.py
Aug 21, 2022
821468f
Printing libsndfile
Aug 21, 2022
7c2304d
Update soundfile_build.py
Aug 21, 2022
eb8bd92
Update soundfile_build.py
Aug 21, 2022
57922c9
Create list_win_paths.yaml
Aug 21, 2022
17abe61
Update soundfile_build.py
Aug 21, 2022
7b7a54d
Delete list_win_paths.yaml
Aug 21, 2022
1b2a8a5
Update windows.yaml
Aug 21, 2022
57aed4f
Update soundfile_build.py
Aug 21, 2022
67aa8bd
Create workflowslist_win_paths.yml
Aug 21, 2022
4db481e
Update and rename workflowslist_win_paths.yml to list_win_paths.yml
Aug 21, 2022
68ea8f1
Rename .github/list_win_paths.yml to .github/workflows/list_win_paths…
Aug 21, 2022
a6bf8ff
Delete python-package.yml
Aug 21, 2022
778dd01
Update list_win_paths.yml
Aug 21, 2022
3bdd158
Update list_win_paths.yml
Aug 21, 2022
09ba166
Update list_win_paths.yml
Aug 21, 2022
a7581e6
Update list_win_paths.yml
Aug 21, 2022
e11c7a5
Update list_win_paths.yml
Aug 21, 2022
8282703
Update list_win_paths.yml
Aug 21, 2022
35e9095
Update soundfile_build.py
Aug 21, 2022
68a9ff6
Update list_win_paths.yml
Aug 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/list_win_paths.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This is a basic workflow to help you get started with Actions
name: Windows Paths
on:
workflow_dispatch:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2019]
python-version:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "pypy-3.7"
- "pypy-3.8"
architecture: ["x86", "x64"]

steps:
- name: Build on Windows
if: runner.os == 'Windows'
# run: |
# choco install libsndfile
# New-Item -ItemType Junction -Path "C:\libsndfile" -Target "C:\Program Files\libsndfile"
# Set-Item -Path Env:LIB -Value "-LC:\libsndfile\bin"
# Set-Item -Path Env:INCLUDE -Value "-IC:\libsndfile\include"
# $Env:windir
# refreshenv
# vswhere.exe -latest -property installationPath
# Get-ChildItem C:\libsndfile\lib
# Get-ChildItem C:\libsndfile\bin
# Get-ChildItem C:\libsndfile\include
# - name: vcpkg build
# uses: johnwason/vcpkg-action@v2
# with:
# pkgs: libsndfile
# triplet: x64-windows-static

run: |
bootstrap-vcpkg
vcpkg install libsndfile
vcpkg integrate install
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- name: Install requirements
run: pip install numpy pytest cffi
- name: Install editable package
run: pip install --editable . --verbose
- name: Run tests
run: python -m pytest
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
name: Python Package
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

on: [push, pull_request]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# name: Python Package

# on: [push, pull_request]

jobs:
test:
Expand Down Expand Up @@ -29,7 +42,21 @@ jobs:
steps:
- name: Install APT dependencies
if: runner.os == 'Linux'
run: sudo apt-get install libsndfile1
run: sudo apt-get install libsndfile1 libsndfile1-dev
# - name: Install choco for Windows
- name: Build on Windows
if: runner.os == 'Windows'
run: |
choco install libsndfile
New-Item -ItemType Junction -Path "C:\libsndfile" -Target "C:\Program Files\libsndfile"
$Env:windir
$Env:INCLUDE
$Env:LIB
$Env:PATH
$Env:PATH += ';C:\libsnfile\bin'
$Env:INCLUDE += ';C:\libsnfile\include'
#Set-Item -Path Env:CGO_LDFLAGS -Value "-LC:\libsndfile\bin"

- uses: actions/checkout@v2
with:
submodules: true
Expand All @@ -38,8 +65,9 @@ jobs:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- name: Install requirements
run: pip install numpy pytest
run: pip install numpy pytest cffi
- name: Install editable package
run: pip install --editable . --verbose
- name: Run tests
run: python -m pytest

70 changes: 70 additions & 0 deletions .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This is a basic workflow to help you get started with Actions
name: Windows Build
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# name: Python Package

# on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2019]
python-version:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "pypy-3.7"
- "pypy-3.8"
architecture: ["x86", "x64"]

steps:
- name: Build on Windows
if: runner.os == 'Windows'
run: |
choco install libsndfile
New-Item -ItemType Junction -Path "C:\libsndfile" -Target "C:\Program Files\libsndfile"
Set-Item -Path Env:LIB -Value "-LC:\libsndfile\bin"
Set-Item -Path Env:INCLUDE -Value "-IC:\libsndfile\include"
$Env:windir
refreshenv
vswhere.exe -latest -property installationPath
Get-ChildItem C:\libsndfile\lib

# $Env:PATH
#Set-Item -Path Env:CFLAGS -Value "C:\libsndfile\include"
# $Env:INCLUDE
# $Env:LIB
# $Env:PATH
# $Env:PATH += ';C:\libsnfile\bin
# $Env:INCLUDE += ';C:\libsnfile\include'
#Set-Item -Path Env:CGO_LDFLAGS -Value "-LC:\libsndfile\bin"

- uses: actions/checkout@v2
with:
submodules: true
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
- name: Install requirements
run: pip install numpy pytest cffi
- name: Install editable package
run: pip install --editable . --verbose
- name: Run tests
run: python -m pytest

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ python:
addons:
apt:
packages:
- libsndfile1
- libsndfile1-dev
install:
- "if [[ $TRAVIS_PYTHON_VERSION == pypy ]]; then pip install git+https://bitbucket.org/pypy/numpy.git ; fi"
script:
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ In 0.9.0, we changed the ``ctype`` arguments of the ``buffer_*``
methods to ``dtype``, using the Numpy ``dtype`` notation. The old
``ctype`` arguments still work, but are now officially deprecated.

In 0.11.0 switched from cffi ABI mode to API mode
Installation
------------

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from setuptools.command.test import test as TestCommand
import sys

from setuptools.extension import Extension

PYTHON_INTERPRETERS = '.'.join([
'cp26', 'cp27',
'cp32', 'cp33', 'cp34', 'cp35', 'cp36',
Expand Down Expand Up @@ -87,7 +89,7 @@ def get_tag(self):

setup(
name='soundfile',
version='0.10.3post1',
version='0.11.1',
description='An audio library based on libsndfile, CFFI and NumPy',
author='Bastian Bechtold',
author_email='[email protected]',
Expand Down
38 changes: 16 additions & 22 deletions soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@
For further information, see https://python-soundfile.readthedocs.io/.

"""
__version__ = "0.10.3"
__version__ = "0.11.1"

import os as _os
import sys as _sys
from platform import machine as _machine
from os import SEEK_SET, SEEK_CUR, SEEK_END
from ctypes.util import find_library as _find_library
from _soundfile import ffi as _ffi
from _soundfile import lib

try:
_unicode = unicode # doesn't exist in Python 3.x
except NameError:
_unicode = str



_str_types = {
'title': 0x01,
'copyright': 0x02,
Expand Down Expand Up @@ -383,7 +385,6 @@ def blocks(file, blocksize=None, overlap=0, frames=-1, start=0, stop=None,
dtype, always_2d, fill_value, out):
yield block


class _SoundFileInfo(object):
"""Information about a SoundFile"""

Expand Down Expand Up @@ -438,7 +439,6 @@ def __repr__(self):

def info(file, verbose=False):
"""Returns an object with information about a `SoundFile`.

Parameters
----------
verbose : bool
Expand All @@ -449,7 +449,6 @@ def info(file, verbose=False):

def available_formats():
"""Return a dictionary of available major formats.

Examples
--------
>>> import soundfile as sf
Expand All @@ -462,28 +461,24 @@ def available_formats():
'WAVEX': 'WAVEX (Microsoft)',
'RAW': 'RAW (header-less)',
'MAT5': 'MAT5 (GNU Octave 2.1 / Matlab 5.0)'}

"""
return dict(_available_formats_helper(_snd.SFC_GET_FORMAT_MAJOR_COUNT,
_snd.SFC_GET_FORMAT_MAJOR))


def available_subtypes(format=None):
"""Return a dictionary of available subtypes.

Parameters
----------
format : str
If given, only compatible subtypes are returned.

Examples
--------
>>> import soundfile as sf
>>> sf.available_subtypes('FLAC')
{'PCM_24': 'Signed 24 bit PCM',
'PCM_16': 'Signed 16 bit PCM',
'PCM_S8': 'Signed 8 bit PCM'}

"""
subtypes = _available_formats_helper(_snd.SFC_GET_FORMAT_SUBTYPE_COUNT,
_snd.SFC_GET_FORMAT_SUBTYPE)
Expand All @@ -493,15 +488,13 @@ def available_subtypes(format=None):

def check_format(format, subtype=None, endian=None):
"""Check if the combination of format/subtype/endian is valid.

Examples
--------
>>> import soundfile as sf
>>> sf.check_format('WAV', 'PCM_24')
True
>>> sf.check_format('FLAC', 'VORBIS')
False

"""
try:
return bool(_format_int(format, subtype, endian))
Expand All @@ -511,20 +504,20 @@ def check_format(format, subtype=None, endian=None):

def default_subtype(format):
"""Return the default subtype for a given format.

Examples
--------
>>> import soundfile as sf
>>> sf.default_subtype('WAV')
'PCM_16'
>>> sf.default_subtype('MAT5')
'DOUBLE'

"""
_check_format(format)
return _default_subtypes.get(format.upper())




class SoundFile(object):
"""A sound file.

Expand Down Expand Up @@ -1205,20 +1198,21 @@ def _open(self, file, mode_int, closefd):

def _init_virtual_io(self, file):
"""Initialize callback functions for sf_open_virtual()."""
@_ffi.callback("sf_vio_get_filelen")
@_ffi.def_extern()
def vio_get_filelen(user_data):
curr = file.tell()
file.seek(0, SEEK_END)
size = file.tell()
file.seek(curr, SEEK_SET)
return size

@_ffi.callback("sf_vio_seek")
@_ffi.def_extern()
def vio_seek(offset, whence, user_data):
file.seek(offset, whence)
return file.tell()

@_ffi.callback("sf_vio_read")
# @_ffi.callback("sf_vio_read")
@_ffi.def_extern()
def vio_read(ptr, count, user_data):
# first try readinto(), if not available fall back to read()
try:
Expand All @@ -1231,7 +1225,7 @@ def vio_read(ptr, count, user_data):
buf[0:data_read] = data
return data_read

@_ffi.callback("sf_vio_write")
@_ffi.def_extern()
def vio_write(ptr, count, user_data):
buf = _ffi.buffer(ptr, count)
data = buf[:]
Expand All @@ -1241,16 +1235,16 @@ def vio_write(ptr, count, user_data):
written = count
return written

@_ffi.callback("sf_vio_tell")
@_ffi.def_extern()
def vio_tell(user_data):
return file.tell()

# Note: the callback functions must be kept alive!
self._virtual_io = {'get_filelen': vio_get_filelen,
'seek': vio_seek,
'read': vio_read,
'write': vio_write,
'tell': vio_tell}
self._virtual_io = {'get_filelen': lib.vio_get_filelen,
'seek': lib.vio_seek,
'read': lib.vio_read,
'write': lib.vio_write,
'tell': lib.vio_tell}

return _ffi.new("SF_VIRTUAL_IO*", self._virtual_io)

Expand Down
Loading